2010-11-26 31 views

回答

1

还有就是,使用

System.Management.Automation 

类库和运行空间。见this MSDN article about creating Runspaces,这里有一个例子,从它在C#:

Runspace runspace = RunspaceFactory.CreateRunspace(); 
runspace.Open(); 

PowerShell powershell = PowerShell.Create(); 
powershell.Runspace = runspace; 
powershell.AddCommand("Get-Process").AddArgument("wmi*"); 

foreach (PSObject result in powershell.Invoke()) 
{ 
    Console.WriteLine("{0,-20}{1}", result.Members["ProcessName"].Value, result.Members["Id"].Value); 
} 

runspace.Close(); 

使用WS-Management this can also be done for a remote host

相关问题