Enable WinRM to run remote Powershell commands

Hey there,

sometimes you’d just like to run Powershell on remote servers but from local console. So you work locally from your PC, but get results from remote computers or servers. It can save you some time automating stuff, doing reports etc.

And nice thing about it is that it can be easily enabled! Here’s how:

On the remote computer, which you want to access:

1) Run Powershell console as Administrator and enable PS Remoting (also starts WinRM service and sets to start automatically  on start)

Enable-PSRemoting -Force

2) Update trusted hosts

Set-Item wsman:\localhost\client\trustedhosts *

This would actually allow any host to connect to this computer. You can limit it to your PC’s IP (v4/v6) address or specific hostname. You can even use wildcards, e.g. “*.contoso.local”.

Now test the connection to this machine from your local PC:

Invoke-Command -ComputerName <hostname/IP> -ScriptBlock { Get-ChildItem C:\ }

Remember the firewall between your PC and remote machine (if there is any) needs to be open for WinRM service.

Have a good day!

Robot(ICT) guy

Published by

Lukas Vu

I started in IT with my own business since high school providing automated and centralized hosting solutions to end customers. Nowadays I'm focusing on corporate area, analyzing, managing and improving customer's IT environments. My main focus nowadays is automation and architectural improvements.

Leave a Reply

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