我是PS的新手,所以我想这里缺少一些基本知识。我可以像这样进行远程Powershell session ...
$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)?
最佳答案
应该适用于Shell uri,并将上下文放入Exchange配置
关于c# - 在C#中创建远程Powershell session ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3216594/