解决 SSL 证书问题后,我得到一个奇怪的异常。请帮忙!我的代码: PSCredential credential = new PSCredential("domain\administrator", securePwd);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://www.xxx.com/powershell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
using (runspace)
{
Collection<PSObject> psObject = GetUserInformation(10, runspace);
}
公共集合 GetUserInformation(int count, Runspace runspace) { using (PowerShell powershell = PowerShell.Create()) {
powershell.AddCommand("Get-Users");
powershell.AddParameter("ResultSize", count);
runspace.Open();//**error happens**
powershell.Runspace = runspace;
return powershell.Invoke();
}
}
错误消息: “连接到远程服务器失败并显示以下错误消息:WinRM 客户端无法处理请求。WinRM 客户端尝试使用协商身份验证机制,但目标计算机 (www.xxx.com:443) 返回了“访问权限” denied' 错误。更改配置以允许使用协商身份验证机制或指定服务器支持的身份验证机制之一。要使用 Kerberos,请将本地计算机名称指定为远程目标。同时验证客户端计算机和目标计算机已加入域。要使用 Basic,请将本地计算机名称指定为远程目标,指定 Basic 身份验证并提供用户名和密码。
我使用基本身份验证,并提供用户名和凭据,为什么它说“尝试使用协商身份验证机制”?