PowerShell e invoke-command

Sep 03 2020

Tenho pelo menos dois problemas nos quais preciso de ajuda.

Nomes curtos vs. longos: posso fazer um nslookup em Serveradmin e Serveradmin.company.com e obter bons endereços IP para ambos.

Problema 1: se eu fizer isso, recebo o seguinte:

Invoke-Command -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Onde {$ _. Grátis -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 linha de comando não funciona com o nome curto ou longo.

Problema 2: agora, se eu fizer isso, recebo o seguinte (com uma SessionOption):

Invoke-Command -ComputerName Serveradmin -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer) -ScriptBlock {Get-PSDrive | Onde {$ _. Grátis -gt 0}}

Recebo bons dados.

Se eu tentar usar o nome longo (Serveradmin.company.com), recebo esta mensagem de erro:

[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 ao servidor proxy que usamos para acesso à web pela Internet?

Alguém pode me ajudar com esses problemas? Eu realmente gostaria de usar nomes curtos e longos.

ATUALIZAR: https://www.pdq.com/powershell/new-pssessionoption/#ProxyAccessType Encontrei esta referência:

Determines which mechanism is used to resolve the host name. 

Alguma idéia de como posso forçar "NoProxyServer" em todos os scripts sem modificar meus scripts?

Respostas

i2D Sep 03 2020 at 16:51

Desative o antivírus no servidor remoto e execute novamente "Invoke-Command -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Where {$ _. Free -gt 0}}"

Os antivírus podem bloquear solicitações HTTP e você precisará descobrir qual configuração precisa ser alterada em seu antivírus.

Veja mais informações aqui: https://mikefrobbins.com/2012/06/21/welcome-to-powershell-hell/