我有一个用于访问远程 PowerShell 的 C# 代码,运行后出现此错误:拒绝访问。代码是:
string shell = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
var target = new Uri("http://Computername/wsman");
Pipeline p = runSpace.CreatePipeline();
SecureString passing = new SecureString();
string password = "pass";
foreach (char c in password)
{
passing.AppendChar(c);
}
passing.MakeReadOnly();
var cred = new PSCredential(@"Domain\User", passing);
var connectionInfo = new WSManConnectionInfo(target, shell, cred); runSpace = RunspaceFactory.CreateRunspace(connectionInfo);
runSpace.Open();
发生此错误是因为我无法访问此地址:http: //schemas.microsoft.com/powershell/Microsoft.PowerShell
输入此地址进行连接后,显示此消息:处理您的请求时发生错误。
是否有其他架构地址或编写此代码的其他方式?
请帮我。谢谢,