2017-04-19 1 views
0

J'ai un script qui ouvre une session distante à l'hôte local. J'ai besoin de cela pour installer NuGet sur certains périphériques à partir d'un logoncript.Echec de la nouvelle session PSSession vers localhost

$Username = "Admin" 
$Password = ConvertTo-SecureString ‘adminPW’ -AsPlainText -Force 
$adminCredential = New-Object System.Management.Automation.PSCredential $Username, $Password 
$Session = New-PSSession -Credential $adminCredential 
Invoke-Command -Session $Session -ScriptBlock {Install-PackageProvider -Name NuGet -Verbose -MinimumVersion 2.8.5.201 -Force} 

Chaque fois que j'essaie d'exécuter ce que je reçois l'erreur suivante:

 
New-PSSession : [localhost] Connecting to remote server localhost failed with the following error message : The client cannot connect to the destination 
specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the 
WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the 
destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic. 
At C:\Users\Mike Holtackers\OneDrive - Foreign Trade Association\Scripts\OutlookSig\getAADconnectionOK.ps1:5 char:12 
+ $Session = New-PSSession -ConnectionUri $ConnectionURI -Credential $a ... 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException 
    + FullyQualifiedErrorId : CannotConnect,PSSessionOpenFailed 

Courir winrm quickconfig ne change rien ...

Voici le résultat de winrm get winrm/config

 
PS WSMan:\localhost\Listener\Listener_1084132640> winrm get winrm/config 
Config 
    MaxEnvelopeSizekb = 500 
    MaxTimeoutms = 60000 
    MaxBatchItems = 32000 
    MaxProviderRequests = 4294967295 
    Client 
     NetworkDelayms = 5000 
     URLPrefix = wsman 
     AllowUnencrypted = false 
     Auth 
      Basic = true 
      Digest = true 
      Kerberos = true 
      Negotiate = true 
      Certificate = true 
      CredSSP = false 
     DefaultPorts 
      HTTP = 5985 
      HTTPS = 5986 
     TrustedHosts = * 
    Service 
     RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD) 
     MaxConcurrentOperations = 4294967295 
     MaxConcurrentOperationsPerUser = 1500 
     EnumerationTimeoutms = 240000 
     MaxConnections = 300 
     MaxPacketRetrievalTimeSeconds = 120 
     AllowUnencrypted = false 
     Auth 
      Basic = false 
      Kerberos = true 
      Negotiate = true 
      Certificate = false 
      CredSSP = false 
      CbtHardeningLevel = Relaxed 
     DefaultPorts 
      HTTP = 5985 
      HTTPS = 5986 
     IPv4Filter = 194.168.254.1-194.168.254.256 [Source="GPO"] 
     IPv6Filter [Source="GPO"] 
     EnableCompatibilityHttpListener = false 
     EnableCompatibilityHttpsListener = false 
     CertificateThumbprint 
     AllowRemoteAccess = true [Source="GPO"] 
    Winrs 
     AllowRemoteShellAccess = true 
     IdleTimeout = 7200000 
     MaxConcurrentUsers = 2147483647 
     MaxShellRunTime = 2147483647 
     MaxProcessesPerShell = 2147483647 
     MaxMemoryPerShellMB = 2147483647 
     MaxShellsPerUser = 2147483647 
+1

Avez-vous couru 'Enable-PSRemoting' sur l'ordinateur? –

+0

Oui, j'ai. J'ai essayé à nouveau d'être le père mais donne toujours le même résultat – Docschnitzel

+1

Avez-vous mis à jour votre WinRM TrustedHosts pour vous permettre de vous connecter à localhost? – TessellatingHeckler

Répondre

0

Problème était quelqu'un avait falsifié le pare-feu ... Merci pour l'aide les gars!

Fondamentalement, le GPO pare-feu bloquait la gestion à distance

+0

Bienvenue sur le site Docschnitzel, pour aider les gens plus loin pouvez-vous essayer et marquer la bonne réponse à votre question originale. Je vois que vous avez réussi à dire que la réponse de @Moewald était correcte, mais vous avez écrit un commentaire disant que cela n'a pas fonctionné, alors vous avez cette autre réponse de vous-même indiquant qu'il s'agissait d'un problème de pare-feu. Qu'avez-vous fait pour résoudre votre problème? Une fois que vous expliquez que vous pouvez ensuite marquer votre propre réponse comme la bonne. –

+0

Merci pour les heads up, j'ai éclairci ma propre réponse et je vais la faire comme la réponse dans quelques heures (quand le site me permettra de la marquer) – Docschnitzel

0

Vérifiez si le service winrm fonctionne sur votre localhost:

PS C:\> Get-Service winrm | ft -AutoSize 

Status Name DisplayName        
------ ---- -----------        
Running winrm Windows Remote Management (WS-Management) 

Sinon PS Remoting ne fonctionnera pas, si vous avez configuré via winrm et avez activé PS Remoting via Enable-PSRemoting.

+0

Il est déjà en cours d'exécution, merci :) Je vais donc devoir creuser plus profondément j'ai peur. – Docschnitzel