Export (0) Print
Expand All

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.

System.Management.Automation.Cmdlet.Invoke
This variant invokes the cmdlet object and returns a collection of "T" type objects.

System.Management.Automation.Cmdlet.Invoke
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.

Examples

 

Example Description

How to Invoke a Cmdlet from Within a Cmdlet

This example shows how to invoke a cmdlet from within another cmdlet.

How to Invoke Scripts Within a Cmdlet

This example shows how to invoke a script that is supplied to the cmdlet from within another cmdlet.

See Also



Community Additions

ADD
Show:
© 2014 Microsoft