2017-09-27 1 views
0

I'am이 코드와 C#을에서 파워 쉘과의 교류에 대한 메일 그룹을 만들려고 :WinRM이 C#의 원격 powershell에 대해 거부되었습니다. cryto가 필요합니까?

private void createDistributionGroup(string groupName, string DNOU) 
    { 
     System.Security.SecureString pass = new System.Security.SecureString("57R0NG_P455W0RD"); 
     PSCredential cred = new PSCredential(SA_username, pass); 
     WSManConnectionInfo connection = new WSManConnectionInfo(new Uri("http://myEXserver.mydomain.com/PowerShell/"), "https://schemas.microsoft.com/powershell/Microsoft.Exchange", cred); 
     connection.AuthenticationMechanism = AuthenticationMechanism.Basic; 
     Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connection); 
     PowerShell ps = PowerShell.Create(); 
     PSCommand command = new PSCommand(); 
     command.AddCommand("New-DistributionGroup"); 
     command.AddParameter("Name", groupName); 
     ps.Commands = command; 
     try 
     { 
      runspace.Open(); 
      ps.Runspace = runspace; 
      ps.Invoke(); 
     } 
     finally 
     { 
      runspace.Dispose(); 
      runspace = null; 
      ps.Dispose(); 
      ps = null; 
     } 
    } 

하지만이 코드를 실행할 때, WinRM이 오류는 추가 : 서버에 의해 거부 연결 forbiden, 암호화되지 않은 트래픽이를 ...

어떻게 해결할 수 있습니까?

답변

0

Kerberos 인증을 사용하려고 했습니까? 기본 인증을 사용해야 할 경우 SSL을 사용해야합니다. 이것은 때때로 올바르게 구성되지 않았으므로 일부 테스트를 수행합니다.

+0

내가 Kerberos 인증 테스트했지만 그것은 arror를 추가 에 –

0

기본 인증을 사용하면 (TomG에서 말한 것처럼) SSL/HTTPS를 사용해야합니다. Kerberos 및 HTTP를 사용하여

WSManConnectionInfo connection = new WSManConnectionInfo(new Uri("**https**://myEXserver.mydomain.com/PowerShell/"), "https://schemas.microsoft.com/powershell/Microsoft.Exchange", cred); 
connection.AuthenticationMechanism = AuthenticationMechanism.Basic; 
connection.ProxyAuthentication = AuthenticationMechanism.Basic; 

는, 프록시 액세스가 없음으로 설정됩니다 : 당신은 아마도 기본에 프록시 인증을 설정해야

WSManConnectionInfo connection = new WSManConnectionInfo(new Uri("**http**://myEXserver.mydomain.com/PowerShell/"), "https://schemas.microsoft.com/powershell/Microsoft.Exchange", cred); 
connection.AuthenticationMechanism = AuthenticationMechanism.Kerberos; 
connection.ProxyAccessType = ProxyAccessType.None; 
관련 문제