2013-04-15 20 views
12

Sto cercando di eseguire codice PowerShell dal computer al VM sul mio computer, ma continuo a ricevere questo errore:Connessione al server remoto non è riuscito utilizzando Gestione remota Windows da 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.

il mio codice:

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(); 

Cosa mi manca?

+0

Hai provato a verificare le cose menzionate nel messaggio di errore? –

risposta

20

Se il client e il computer remoto non sono sullo stesso dominio, si dispone di una delle due opzioni:

  • utilizzo HTTPS come protocollo di trasporto
  • aggiungere il computer remoto all'elenco dei host attendibili sul client

per configure WinRM utilizzare HTTPS, aprono una console PowerShell come amministratore su entrambe le macchine ed eseguire:

winrm quickconfig -transport:https 

e aperto la porta 5986 sul firewall:

netsh firewall add portopening TCP 5986 "WinRM over HTTPS" 

In alternativa, è possibile aggiungere la macchina remota come ospite di fiducia sul client eseguendo:

winrm set winrm/config/client '@{TrustedHosts="10.0.5.35"}' 
+0

sì, ho capito: "WinRM è già configurato per ricevere richieste su questa macchina. WinRM è già impostato per la gestione remota su questa macchina." – woolford

+0

@woolford sono client e server nello stesso dominio? –

+0

Enrico Campidoglio no sir – woolford

1

hai abilitato winrm su entrambe le macchine? prova a eseguire winrm quickconfig su ogni macchina per garantire che la connettività remota sia abilitata.

+0

sì, ho capito: "WinRM è già configurato per ricevere richieste su questa macchina. WinRM è già impostato per la gestione remota su questa macchina." – woolford

+0

Provare a utilizzare l'autenticazione CredSSP. Guarda i passaggi nella mia risposta: http://stackoverflow.com/questions/15336336/running-batch-file-on-remote-computers-using-powershell-2-0/15336790#15336790 –

+0

CredSSP è usato per consentire alla macchina remota di trasmettere le credenziali del client quando ci si connette ad altri servizi (ad esempio un [secondo salto] (http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/14/enable-powershell- quot secondi-hop-quot-funzionalità-con-credssp.aspx)). Il problema in questo caso è che il client e il server non si trovano sullo stesso dominio. –

Problemi correlati