PSRemoting传输异常 [英] PSRemoting Transport Exception

查看:129
本文介绍了PSRemoting传输异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图使用C#运行Exchange Server 2010监视命令.这是我的代码...

Hello All,

I was trying to run exchange server 2010 monitoring commands using C#. Here is my code...

string password = "abc123"; 
string userName = @"me.com\Administrator";
System.Uri uri = new Uri("http://192.168.1.194/powershell?serializationLevel=Full");
System.Security.SecureString securePassword = String2SecureString(password);
System.Management.Automation.PSCredential creds = new System.Management.Automation.PSCredential(userName, securePassword);
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("New-PSSession");
command.AddParameter("ConfigurationName", "Microsoft.Exchange");
command.AddParameter("ConnectionUri", uri);
command.AddParameter("Credential", creds);
command.AddParameter("Authentication", "Default");
PSSessionOption sessionOption = new PSSessionOption();
sessionOption.SkipCACheck = true;
sessionOption.SkipCNCheck = true;
sessionOption.SkipRevocationCheck = true;
command.AddParameter("SessionOption", sessionOption);
powershell.Commands = command;
try
   {
       runspace.Open();
       powershell.Runspace = runspace;
       Collection<PSSession> result = powershell.Invoke<PSSession>();
       foreach (ErrorRecord current in powershell.Streams.Error)
       {
             throw new Exception("Exception: " + current.Exception.ToString());
       }
       if (result.Count != 1)
          throw new Exception("Unexpected number of Remote Runspace connections    
          returned.");
 
       powershell = PowerShell.Create();
       command = new PSCommand();
       command.AddCommand("Set-Variable");
       command.AddParameter("Name", "ra");
       command.AddParameter("Value", result[0]);
       powershell.Commands = command;
       powershell.Runspace = runspace;
       powershell.Invoke();
 
       powershell = PowerShell.Create();
       command = new PSCommand();
       command.AddScript("Import-PSSession -Session $ra");
       powershell.Commands = command;
       powershell.Runspace = runspace;
       powershell.Invoke();
 
       System.Collections.ObjectModel.Collection<PSObject> results = new 
       System.Collections.ObjectModel.Collection<PSObject>();
 
       powershell = PowerShell.Create();
       powershell.Runspace = runspace;
 
       System.IO.StreamReader sr = new System.IO.StreamReader("..\\..\\Script.ps1");
       powershell.AddScript(sr.ReadToEnd());
       powershell.Runspace.SessionStateProxy.SetVariable("proc", "C*");
       powershell.Runspace.SessionStateProxy.SetVariable("mbx", "*MBX");
 
       results = powershell.Invoke();
 
       if (powershell.Streams.Error.Count > 1)
       {
           foreach (ErrorRecord er in powershell.Streams.Error)
                  Console.WriteLine(er.ErrorDetails);
       }
       else
       {
           foreach (PSObject ps in results)
           {
                   Console.WriteLine(ps.Properties["Name"].Value.ToString());
           }
       }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        runspace.Dispose();
        runspace = null;
        powershell.Dispose();
        powershell = null;
     }



但是我遇到了以下错误...



But I have got the following error...

Exception: System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server failed with the following error message : The WinRM client cannot process the request. The WinRM client tried to use Negotiate authentication mechanism, but the destination computer (192.168.1.194:80) returned an 'access denied' error. Change the configuration to allow Negotiate authentication mechanism to be used or specify one of the authentication mechanisms supported by the server. To use Kerberos, specify the local computer name as the remote destination. Also verify that the client computer and the destination computer are joined to a domain. To use Basic, specify the local computer name as the remote destination, specify Basic authentication and provide user name and password. Possible authentication mechanisms reported by server: For more information, see the about_Remote_Troubleshooting Help topic.



解决这个问题的任何帮助都会很棒...

谢谢&问候

Sebastian



Any help to solve this would be great...

Thanks & Regards

Sebastian

推荐答案

ra"); powershell.Commands =命令; powershell.Runspace =运行空间; powershell.Invoke(); System.Collections.ObjectModel.Collection< PSObject>结果= System.Collections.ObjectModel.Collection< PSObject>(); powershell = PowerShell.Create(); powershell.Runspace =运行空间; System.IO.StreamReader sr = System.IO.StreamReader(" ); powershell.AddScript(sr.ReadToEnd()); powershell.Runspace.SessionStateProxy.SetVariable(" " ); powershell.Runspace.SessionStateProxy.SetVariable(" " ); 结果= powershell.Invoke(); 如果(powershell.Streams.Error.Count > 1 ) { foreach (在 powershell.Streams.Error中,> Console.WriteLine(er.ErrorDetails); } 其他 { foreach (PSObject ps in 结果) { Console.WriteLine(ps.Properties [" ].Value.ToString()); } } } 捕获(例外) { MessageBox.Show(ex.Message); } 最终 { runspace.Dispose(); runspace = ; powershell.Dispose(); powershell = ; }
ra"); powershell.Commands = command; powershell.Runspace = runspace; powershell.Invoke(); System.Collections.ObjectModel.Collection<PSObject> results = new System.Collections.ObjectModel.Collection<PSObject>(); powershell = PowerShell.Create(); powershell.Runspace = runspace; System.IO.StreamReader sr = new System.IO.StreamReader("..\\..\\Script.ps1"); powershell.AddScript(sr.ReadToEnd()); powershell.Runspace.SessionStateProxy.SetVariable("proc", "C*"); powershell.Runspace.SessionStateProxy.SetVariable("mbx", "*MBX"); results = powershell.Invoke(); if (powershell.Streams.Error.Count > 1) { foreach (ErrorRecord er in powershell.Streams.Error) Console.WriteLine(er.ErrorDetails); } else { foreach (PSObject ps in results) { Console.WriteLine(ps.Properties["Name"].Value.ToString()); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { runspace.Dispose(); runspace = null; powershell.Dispose(); powershell = null; }



但是我遇到了以下错误...



But I have got the following error...

Exception: System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server failed with the following error message : The WinRM client cannot process the request. The WinRM client tried to use Negotiate authentication mechanism, but the destination computer (192.168.1.194:80) returned an 'access denied' error. Change the configuration to allow Negotiate authentication mechanism to be used or specify one of the authentication mechanisms supported by the server. To use Kerberos, specify the local computer name as the remote destination. Also verify that the client computer and the destination computer are joined to a domain. To use Basic, specify the local computer name as the remote destination, specify Basic authentication and provide user name and password. Possible authentication mechanisms reported by server: For more information, see the about_Remote_Troubleshooting Help topic.



解决这个问题的任何帮助都会很棒...

谢谢&问候

Sebastian



Any help to solve this would be great...

Thanks & Regards

Sebastian


您遇到的是身份验证问题.我认为这样可以帮助您:

http://social.technet.microsoft.com/wiki/contents/articles/8004.scom-2007-exchange-2010-how-to-resolvetest-powershellconnectivity-errors.aspx [ http://social.technet.microsoft.com/论坛/en-US/winserverManagement/thread/989af433-3b23-47b7-bfe8-4d84869027d3 [
What you have here is an authentication issue. I think this like will be able to help you out:

http://social.technet.microsoft.com/wiki/contents/articles/8004.scom-2007-exchange-2010-how-to-resolvetest-powershellconnectivity-errors.aspx[^]

Here is another link that might help you out:

http://social.technet.microsoft.com/Forums/en-US/winserverManagement/thread/989af433-3b23-47b7-bfe8-4d84869027d3[^]


这篇关于PSRemoting传输异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆