How to Enable PowerShell Remoting in Easy Way

Empower yourself with the ability to perform administrative tasks on multiple servers remotely, even while users are logged in or away. PowerShell remoting, available since PowerShell version 2 and above, opens up a world of possibilities for system administrators.

If you’re using Windows 7, 2008R2, or newer, PowerShell remoting is already at your fingertips. However, for legacy environments like Server 2003 and Windows XP, a few additional steps are required. You’ll need to install the Server 2003 Service Pack 2 and the Windows Management Framework.

Things to do on the destination computer

This is the computer on which you want to execute the remote commands. On this machine, run PowerShell as an administrator and execute the command.

Set-ExecutionPolicy RemoteSigned

Then, initialize WinRM with the following command:

winrm quickconfig -quiet

On the source computer, you’ll also need to start the WinRM service temporarily to configure settings. Remember to add the destination computers to the trusted hosts list for communication. This ensures a secure connection between local and remote systems. Other words, 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 would be more efficient to enroll the certificate via GPO in domain environment. I’ll write the other article for this scenario)

Things to do on Source Computer

This is the computer that will initiate the connection. In the elevated PowerShell session of source computer, type:

winrm quickconfig -quiet
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.*"

Figure 1:  WinRM Quick Configuration

Figure 2: Added Computers to Trusted Hosts

Let’s 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 -Credential (Get-Credential) -Authentication default

Figure 3: Testing the Connection

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.

Leave a Reply

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