Invoking Cmdlets and Scripts Within a Cmdlet
A cmdlet can invoke other cmdlets and scripts from within the input processing method of the cmdlet. This allows you to add the functionality of existing cmdlets and scripts to your cmdlet without having to rewrite the code.
The Invoke Method
All cmdlets can invoke an existing cmdlet by calling the System.Management.Automation.Cmdlet.Invoke method from within an input processing method, such as BeginProcessing, that is overridden by the cmdlet. However, you can invoke only those cmdlets that derive directly from the Cmdlet class. You cannot invoke a cmdlet that derives from the PSCmdlet class.
The Invoke method has the following variants.
- This variant invokes the cmdlet object and returns a collection of "T" type objects.
- This variant invokes the cmdlet object and returns a strongly typed emumerator. This variant allows the user to use the objects in the collection to perform custom operations.
This example shows how to invoke a cmdlet from within another cmdlet.
This example shows how to invoke a script that is supplied to the cmdlet from within another cmdlet.
Other ResourcesWriting a Windows PowerShell Cmdlet