2010-11-26 53 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

相關問題