Connect to Remote Machine via WinRM (PowerShell PSSession)

Unlike SSH, connecting to a remote host with WinRM requires a little bit of a setup.
Since this is required for chef test kitchen set up, and I end up re-Googling for this every time I set up a new machine, I decided it is worth a blog post.

So there are potentially two parts to this, dependent on whether WinRM is already set up on your machine:

Connect to remote machine

First set up your credentials. Open up PowerShell and run

 $cred = Get-Credential

This will prompt you for your credentials and save them in the $cred variable. Enter the credentials you intend to use to connect to the remote machine.
Now enter PSSession using your remote host IP and the credentials you have just set up:

 Enter-PSSession 192.168.XXX.XXX -Authentication "basic" -Credential=$cred

If you get the error:

The WinRM client cannot process the request…

Continue reading on how to set up WinRM on your machine:

Set up WinRm on your machine

Open CMD as administrator
Enable WinRM

winrm quickconfig /q

To check your current WinRM configuration

winrm get winrm/config

If you get the error:

The WinRM client cannot process the request. Unencrypted traffic is currently disabled in the client configuration.

Enable unencrypted traffic in WinRM:

winrm set winrm/config/client @{AllowUnencrypted="true"}

If you get the error:

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.

Add the remote computer you are connecting to to Trusted hosts:

winrm set winrm/config/client @{TrustedHosts="192.168.XXX.XXX"}

If you do this fairly often and are behind a secure firewall you can save some time by adding everyone to your trusted hosts:

winrm set winrm/config/client @{TrustedHosts="*"}

Happy Remoting!

No, wait, the mandatory meme:

remote session

One thought on “Connect to Remote Machine via WinRM (PowerShell PSSession)

Leave a Reply

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