When Enable-PSRemoting fails
The ability to remotely execute commands is crucial for system admins.
This blog post is just a superficial review of this particular issue that I encounter occasionally whenever I try to run Enable-PSRemoting – but it fails.
In the command output, there’s a single white line that states
WinRM is already set up to receive requests on this computer.
Followed by an error message block. Which is somewhat confusing, because it looks like it did something and worked… but also didnt?
As a young system admin, I used to just look at the wall of red text as a singular “ERROR” wall, refuse to read it, and keep trying other things – figuratively and literally throwing various google-fu crap at the system until something sticks.
These days, I know better. (…usually)
If we actually look closely at the red text, it clearly states that:
WinRM firewall exception will not work since one of the network connection types on this machine is set to Public. Change the network connection type to either Domain or Private and try again.
So… seems PSremoting can’t be enabled because of a network connection type. But, how do I fix that?
Get-NetAdapter
First thing I checked was Get-NetAdapter
But not a lot there.
Get-NetConnectionProfile
Then I tried Get-NetConnectionProfile
From the output, I can see network interface index 16 is set to NetworkCategory: Public. That seems to be what’s causing the error.
But now what?
Peeking at the Related Links section of the online help page for Get-NetConnectionProfile, we see a link to Set-NetConnectionProfile. That should be a clue.
Set-NetConnectionProfile
With Set-NetConnectionProfile it’s possible to programatically modify the connection type/category.
After setting the network category to “Private”, I’m able to successfully run Enable-PSRemoting -Force this time.
Summary
From a Microsoft web page about network settings
Public network (Recommended). Use this for networks you connect to at home, work, or in a public place. You should use this in most cases. Your PC will be hidden from other devices on the network. Therefore, you can’t use your PC for file and printer sharing.
Private network. Your PC is discoverable to other devices on the network, and you can use your PC for file and printer sharing. You should know and trust the people and devices on the network.
There’s more to it than just these two definitions, but that’s good enough for this post.
References:
Enable-PSRemoting
Get-NetAdapter
Get-NetConnectionProfile
Set-NetConnectionProfile
about_PSSessions
about_PSSession_Details
about_Remote_Troubleshooting
Chapter 8 - PowerShell remoting