以下代碼運行:的PowerShell遠程命令失敗,因爲未加密流量的
SecureString password = new SecureString();
string runasUsername = "USERNAME";
string runasPassword = "PASSWORD";
string liveIdconnectionUri = "http://EXCHANGE_SERVER/PowerShell";
foreach (char x in runasPassword)
{
password.AppendChar(x);
}
PSCredential credential = new PSCredential(runasUsername, password);
// Set the connection Info
WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic; //AuthenticationMechanism.Default;
// create a runspace on a remote path
// the returned instance must be of type RemoteRunspace
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("Enable-Mailbox");
command.AddParameter("Identity", "first.last");
command.AddParameter("Alias", "Fist Last");
powershell.Commands = command;
try
{
// open the remote runspace
runspace.Open();
// associate the runspace with powershell
powershell.Runspace = runspace;
// invoke the powershell to obtain the results
var result = powershell.Invoke();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// dispose the runspace and enable garbage collection
runspace.Dispose();
runspace = null;
// Finally dispose the powershell and set all variables to null to free
// up any resources.
powershell.Dispose();
powershell = null;
}
Console.WriteLine("done");
Console.Read();
例外拋出:
連接到具有以下錯誤消息出現故障的遠程服務器: WinRM的客戶端無法處理請求。未加密的流量是當前在客戶端配置中禁用的 。更改客戶端 配置並再次嘗試請求。有關更多信息,請參閱 about_Remote_Troubleshooting幫助主題。
我已經設置了基本身份驗證,允許未加密的流量。
我試過這裏的解決方案powershell v2 remoting - How do you enable unencrypted traffic,沒有運氣。
基本是明文(未加密)認證類似的,當你得到一個網站上popupbox來。 WS-man的默認值是在域中使用Kerberos(加密)或在非域計算機之間進行協商。 – 2013-02-25 07:26:00
謝謝格雷默。 – unruledboy 2013-03-02 13:23:24