我對PS很新,所以我想我在這裏缺少一些基本的東西。我可以做這樣的遠程PowerShell會話...在C#中創建遠程PowerShell會話?
$Session = New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri https://remote.com/Powershell
-Credential "Domain\Admin"
我想在C#中相當於所以我想這一點,但它不工作...
WSManConnectionInfo connInfo = new WSManConnectionInfo(
new Uri("https://remote.com/Powershell"), /* uri */
"/wtf", /* shellUri??? */
cred); /* ps-credential */
using (Runspace runspace = RunspaceFactory.CreateRunspace(connInfo))
{
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = runspace;
}
}
這種失敗...
System.Management.Automation.Remoting.PSRemotingTransportException was unhandled
Message=Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. The resource URI (/wsman) was not found in the WS-Management catalog....
如何將它轉換爲C#?什麼是「shellUri」參數,以及如何傳達配置名稱(在我的情況下是Microsoft.Exchange)?
哦,我明白了,所以在C#中指定這個「shell uri」相當於將ConfigurationName設置爲Powershell中的Microsoft.Exchange? – noctonura 2010-07-09 21:20:57