
Part IV: Automating Administration
490
add a parameter to the Get-Mailbox command. For instance, if you need to run Get-Mailbox -Server
MB001
, you need to use the pipeline.command.add method to add in Get-Mailbox as the command
that needs to run and then use the
command.Parameters.Add method to add Server and MB001 to
modify that command. The
CommandParameter class requires only a name in the case of a switch param-
eter and a name and a value for parameters that have additional values:
Runspace EMSRunSpace = RunspaceFactory.CreateRunspace();
EMSRunSpace.Open();
Pipeline pipeLine = EMSRunSpace.CreatePipeline();
Command MBXCommand = new Command(“Get-Mailbox”);
pipeLine.Commands.Add(MBXCommand);
CommandParameter verbParam = new CommandParameter(“Server”,
“MB001”);
EMSCmd.Parameters.Add(verbParam);
Command FTCommand = new Command(“Format-Table”);
pipeLine.Commands.Add(FTCommand);
Collection < PSObject > cmdResult = pipeLine.Invoke();
When adding commands to a pipeline this way, take care to ensure that the command is being passed
correctly typed data. Most of the cmdlets accept standard Int64, string, or byte quantified size for their
parameter values. However, a number of Exchange cmdlets have the
filterscript parameter and
this parameter requires a value typed as a
ScriptBlock and will not accept a string value. Creating a
ScriptBlock value isn ’ t as straightforward ...