我想從我的電腦運行PowerShell代碼到VM我的電腦上失敗了,但我不斷收到此錯誤:連接到遠程服務器中使用WinRM的從PowerShell的
Connecting to remote server failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
我的代碼:
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();
我錯過了什麼?
你有沒有試圖檢查錯誤信息中提到的東西? –