我想在C#項目中使用此PowerShell命令:插入PowerShell命令到C#
Get-VM -Name Win8-Henry | Get-VMNetworkAdapter | Select MacAddress
這是我常做的在C#:
public static void MacAdd(string machineName,Runspace run) {
// Get-VM -Name Win8-Henry | Get-VMNetworkAdapter | Select MacAddress
Command command = new Command("Get-VM");
command.Parameters.Add("Name", machineName);
using (Pipeline hostPipeline = run.CreatePipeline())
{
hostPipeline.Commands.Add(command);
Collection<PSObject> echos = hostPipeline.Invoke();
hostPipeline.Stop();
}
}
我需要什麼是幫助添加第二個命令,然後使用管道。
hostPipeline.Commands.Add (anotherCommand)然後調用()? – NValchev