我正在尝试将 powershell 代码从我的计算机运行到我计算机上的 vm,但我不断收到此错误:
连接到远程服务器失败并显示以下错误消息:WinRM 客户端无法处理请求。如果身份验证方案与 Kerberos 不同,或者客户端计算机未加入域,则必须使用 HTTPS 传输或将目标计算机添加到 TrustedHosts 配置设置。使用 winrm.cmd 配置 TrustedHosts。请注意,TrustedHosts 列表中的计算机可能未经过身份验证。您可以通过运行以下命令获得更多信息:winrm help config。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。
我的代码:
string runasUsername = @"\aaa";
string runasPassword = "aaa";
SecureString ssRunasPassword = new SecureString();
foreach (char x in runasPassword)
ssRunasPassword.AppendChar(x);
PSCredential credentials = new PSCredential(runasUsername, ssRunasPassword);
var connInfo = new WSManConnectionInfo(new Uri("http://10.0.5.35/PowerShell"),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",credentials);
connInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
var runspace = RunspaceFactory.CreateRunspace(connInfo);
var domainName = "domainName.COM";
var password = "ActiveDirectoryPassword1234";
var ssPassword = new SecureString();
foreach (char c in password)
ssPassword.AppendChar(c);
var command = new Command("New-Mailbox");
command.Parameters.Add("FirstName", firstName);
command.Parameters.Add("LastName", lastName);
command.Parameters.Add("Password", ssPassword);
command.Parameters.Add("ResetPasswordOnNextLogon", false);
command.Parameters.Add("OrganizationalUnit", "NeumontStudents");
runspace.Open(); <--//error here
var pipeline = runspace.CreatePipeline();
pipeline.Commands.Add(command);
var results = pipeline.Invoke();
runspace.Dispose();
我错过了什么?