PowerShell et invoke-command
J'ai au moins deux problèmes pour lesquels j'ai besoin d'aide.
Noms courts ou longs: je peux faire un nslookup sur Serveradmin et Serveradmin.company.com et obtenir de bonnes adresses IP pour les deux.
Problème 1: si je fais cela, j'obtiens ceci:
Invoke-Command -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Où {$ _. Free -gt 0}}
[Serveradmin] Connecting to remote server Serveradmin failed with the
following error message : WS-Management cannot process the request.
The operation failed because of an HTTP error. The HTTP error (12152)
is: The server returned an invalid or unrecognized response . For
more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (Serveradmin:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationAborted,PSSessionStateBroken
Cette ligne de commande ne fonctionne pas avec le nom court ou long.
Problème 2: Maintenant, si je fais cela, j'obtiens ceci (avec une SessionOption):
Invoke-Command -ComputerName Serveradmin -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer) -ScriptBlock {Get-PSDrive | Où {$ _. Free -gt 0}}
J'obtiens de bonnes données.
Si j'essaie d'utiliser le nom long (Serveradmin.company.com), j'obtiens ce message d'erreur:
[Serveradmin.lmms.lmco.com] Connecting to remote server lc1admin.lmms.lmco.com failed with the following error message : WinRM cannot process the request. The following error occurred while using Kerberos authentication: Cannot find
the computer Serveradmin.lmms.lmco.com. Verify that the computer exists on the network and that the name provided is spelled correctly. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (Serveradmin.lmms.lmco.com:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken
Q3: "Proxy" équivaut-il au serveur proxy que nous utilisons pour l'accès Web à Internet?
Quelqu'un peut-il m'aider avec ces problèmes? J'aimerais vraiment utiliser des noms courts et longs.
METTRE À JOUR: https://www.pdq.com/powershell/new-pssessionoption/#ProxyAccessType J'ai trouvé cette référence:
Determines which mechanism is used to resolve the host name.
Des idées sur la façon dont je peux forcer "NoProxyServer" sur tous les scripts sans modifier mes scripts?
Réponses
Désactivez votre antivirus sur le serveur distant et relancez "Invoke-Command -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Where {$ _. Free -gt 0}}"
Les antivirus peuvent bloquer les requêtes HTTP et vous devrez déterminer la configuration à modifier sur votre AV.
Voir plus d'informations ici: https://mikefrobbins.com/2012/06/21/welcome-to-powershell-hell/