PDA

View Full Version : Remote PowerShell esempi


c3n2o
01-08-2016, 08:58
Buongiorno a tutti,
mi hanno chiesto se in un server win 2008/2012 è possibile attivare il PowerShell Remoto.

Ho cercato su google e ho trovato alcune risposte, in particolar modo questi due comandi:
winrm s winrm/config/client '@{TrustedHosts="ComputerRemoto"}'
Set-Item WSman:\localhost\client\TrustedHosts\ -value "*" -Force
ma quello che mi manca sono esempi di comandi PowerShell remoti o per la connessione al sistema remoto per fare le prove sui nostri sistemi.

Nel cercare una guida ho trovato una pagina MS dove dice di guarddare sui sistemi Win2008 la guida introduttiva.. ma nei sistemi che abbiamo non c'è:confused:

Inoltre mi domandavo se PowerShell avesse bisogno di porte particolari per funzionare o se usa le porte di RemoteDesktop..

:help:
Grazie


edit
Ho trovato le porte di default:
TCP/5985 = HTTP

TCP/5986 = HTTPS

Ma si possono cambiare..

c3n2o
01-08-2016, 13:55
Ciao a tutti,
Ho trovato il comando più semplice (presumo):
Enter-PSSession -ComputerName gigi

Ma non funziona:muro: :muro:

Allora sul server win2012 di nome gigi ho dato (spero) i permessi del firewall e inoltre con gpedit ho modificato (sotto "computer config>Admin Templates> Network> Network connections>Windows firewall> Domain Profile") la voce windows firewall: Define inbound program exception aggiungendo le 2 porte (in realtà nella guida che ho trovato c'era solo la prima porta)

5985:TCP:*:Enabled:WinRM
5986:TCP:*:Enabled:WinRM

Ma quando provo a connettermi con la powershell del mio PC (che è un Windows 7) mi da il seguente errore
PS C:\Windows\system32> Enter-PSSession -ComputerName gigi
Enter-PSSession : Connecting to remote server failed with the following error
message : The WinRM client cannot process the request. If the authentication
scheme is different from Kerberos, or if the client computer is not joined to a
domain, then HTTPS transport must be used or the destination machine must
be added to the TrustedHosts configuration setting. Use winrm.cmd to
configure TrustedHosts. Note that computers in the TrustedHosts list might
not be authenticated. You can get more information about that by running the
following command: winrm help config. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:16
+ Enter-PSSession <<<< -ComputerName gigi
+ CategoryInfo : InvalidArgument: (gigi:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed


Mentre se faccio ping gigi, funziona correttamente.

Dove sto sbagliando?
Devo abilitare forse qualcosa anche nel mio PC?

Grazie ancora

sypher01
25-08-2016, 12:23
Ma scusa, questi due computer sono nello stesso dominio?

Dal computer dal quale vuoi accedere, il 'ping gigi' ti funziona? Il DNS è a posto?

c3n2o
26-08-2016, 09:00
Ciao,
Sì, nel test che sto facendo sono sullo stesso dominio.. ma poi nella pratica mi sa di no.. o per lo meno uno dei PC dovrà essere collegato tramite VPN alla rete del server (dove mandare i comandi PowerShell)

Cmq il problema era che dovevo farmi chiedere la pwd.. quindi ho risolto col comando:
Enter-PSSession –ComputerName RemoteHost –Credential User

Ma dici che essendo su rete VPN (ancora noi non abbiamo provato) potrebbe non funzionare?

Grazie

sypher01
26-08-2016, 14:38
Su VPN funziona se passano le porte giuste; se non hai fw di mezzo non avrai problemi.

Sul discorso credential, lui di default usa il tuo utente.

Ovviamente se il tuo utente non ha accesso alla macchina a cui vuoi collegarti, devi specificare che utente vuoi utilizzare.

Ad ogni modo vale quanto sopra!