以下代码运行:的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