The commands or cmdlets and their
parameters can be added on the fly to the pipeline. This is accomplished by instantiating command objects
from the Command class and then adding the command to the pipelines collection of commands. The
command object (which equates to a cmdlet or pre - written script) in turn might require a set of parameters.
The way command parameters are added to a command is very simular to the way commands are
added to the pipeline. First instantiate a CommandParameter object from the CommandParameter class,
passing the list of parameters to its constructor. Then add the CommandParameter object to the
command ??™ s parameters collection. This example shows how to create a runspace and then add the
get-mailbox command without any parameters:
Runspace EMSRunSpace = RunspaceFactory.CreateRunspace();
EMSRunSpace.Open();
Pipeline pipeLine = EMSRunSpace.CreatePipeline();
Command MBXCommand = new Command(???Get-Mailbox???);
pipeLine.Commands.Add(MBXCommand);
Collection < PSObject > cmdResult = pipeLine.Invoke();
To add multiple commands to the pipeline, a new command object must be created for each command
and then added to the pipeline. In the following example the MBXCommand object is created for the
Get-Mailbox command and then added to the pipeline.
Pages:
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681