PowerShell e invoke-command

Sep 03 2020

Ho almeno due problemi per i quali ho bisogno di aiuto.

Nomi brevi o lunghi: posso fare un nslookup su Serveradmin e Serveradmin.company.com e ottenere buoni indirizzi IP per entrambi.

Problema 1: se lo faccio, ottengo questo:

Richiamare-Comando -NomeComputer Serveradmin -ScriptBlock {Get-PSDrive | Dove {$ _. 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

Questa riga di comando non funziona con il nome breve o lungo.

Problema 2: ora se lo faccio ottengo questo (con una SessionOption):

Richiamare-Comando -ComputerName Serveradmin -SessionOption (New-PSSessionOption -ProxyAccessType NoProxyServer) -ScriptBlock {Get-PSDrive | Dove {$ _. Free -gt 0}}

Ottengo buoni dati.

Se provo a utilizzare il nome lungo (Serveradmin.company.com), ricevo questo messaggio di errore:

[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

D3: "Proxy" equivale al server proxy che utilizziamo per l'accesso web a Internet?

Qualcuno può aiutarmi con questi problemi? Mi piacerebbe davvero usare nomi brevi e lunghi.

AGGIORNARE: https://www.pdq.com/powershell/new-pssessionoption/#ProxyAccessType Ho trovato questo riferimento:

Determines which mechanism is used to resolve the host name. 

Delle idee su come posso forzare "NoProxyServer" su tutti gli script senza modificare i miei script?

Risposte

i2D Sep 03 2020 at 16:51

Disabilita il tuo antivirus sul server remoto ed esegui di nuovo "Invoke-Command -ComputerName Serveradmin -ScriptBlock {Get-PSDrive | Where {$ _. Free -gt 0}}"

Gli antivirus possono bloccare le richieste HTTP e dovrai capire quale configurazione deve essere modificata sul tuo AV.

Vedi ulteriori informazioni qui: https://mikefrobbins.com/2012/06/21/welcome-to-powershell-hell/