PowerShell Remoting Made Easy !

With Powershell Remoting, you can do administrative tasks on bunch of servers remotely or in the background while the client users are currently logged in or not.
PowerShell remoting is supported since PowerShell version 2 and above, which is from windows7, 2008R2 and above. If you want to use the PowerShell remoting in server 2003 and windows XP environment, you first need to install the Server2003 Service Part 2 and Windows Management Framework. You can go and download these packages from Microsoft Website.
https://www.microsoft.com/en-us/download/details.aspx?id=41
https://www.microsoft.com/en-us/download/details.aspx?id=4045

1) On Destionation computer (the computer you want to manage)
click windows powershell > run as administrator
Set-ExecutionPolicy RemoteSigned
type winrm quickconfig quiet(or) winrm qc -q

On Source computer, you also need to start the winrm service to configure service setting, but it is only for configuring services so you can disable the service later. Another thing is, the communication between local and remote computer is by default unencrypted, so you need to explicitly add the destionation computers to the trusted list on source computer. In trustedhosts list, you can define the destination computers by IP addresses separated by commas or using wildcard as follows.
(Note: if you use the HTTPs, you need to generate the certificate and add to each computer, so it is more handy to enroll the certificate via GPO in domain environment. I’ll write the other article for this scenario)

2) On the Source Computer
click windows powershell > run as administrator
In powershell, type winrm qc -q
set-item wsman:localhostclienttrustedhosts “192.168.1.*”

 
Figure 1:  WinRM Quick Configuration


Figure 2: Added Computers to Trusted Hosts

3) Test the Connection
you can use Test-WSman to test if the powershell remoting works. The following command will test the connection.
Test-WSman -ComputerName 192.168.1.222 -Credential (Get-Credential) -Authentication default


Figure 3: Testing the Connection

4) Using remote script execution (example)
You can execute remote scripts on multiple computers, you can put the computers names as IPs or hostnames in text file. Here is the one I show as example.

This entry was posted in Powershell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *