PowerShell e invoke-command
Tengo al menos dos problemas con los que necesito ayuda.
Nombres cortos o largos: puedo hacer un nslookup en Serveradmin y Serveradmin.company.com y obtener buenas direcciones IP para ambos.
Problema 1: si hago esto, obtengo esto:
Invocar-Comando -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Donde {$ _. 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
Esta línea de comando no funciona con el nombre corto o largo.
Problema 2: Ahora, si hago esto, obtengo esto (con una opción de sesión):
Invocar-Comando -ComputerName Serveradmin -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer) -ScriptBlock {Get-PSDrive | Donde {$ _. Free -gt 0}}
Obtengo buenos datos.
Si intento usar el nombre largo (Serveradmin.company.com), aparece este mensaje de error:
[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
P3: ¿"Proxy" equivale al servidor proxy que usamos para el acceso web a Internet?
¿Alguien puede ayudarme con estos problemas? Realmente me gustaría usar nombres cortos y largos.
ACTUALIZAR: https://www.pdq.com/powershell/new-pssessionoption/#ProxyAccessType Encontré esta referencia:
Determines which mechanism is used to resolve the host name.
¿Alguna idea de cómo puedo forzar "NoProxyServer" en todos los scripts sin modificar mis scripts?
Respuestas
Desactive su antivirus en el servidor remoto y vuelva a ejecutar "Invoke-Command -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Where {$ _. Free -gt 0}}"
Los antivirus pueden bloquear las solicitudes HTTP, y deberá determinar qué configuración debe cambiarse en su AV.
Vea más información aquí: https://mikefrobbins.com/2012/06/21/welcome-to-powershell-hell/