Change network connection category using PowerShell

Note: This blogpost is also posted on my personal blog – https://itmicah.wordpress.com

 

refwin-advfirewall-img4

I recently came across an issue with PSRemoting to a Windows 7 XenDesktop VM. I discovered remoting was disabled on the remote system because one of the network connections was a Public connection (it was the PVS connection). To change this using PowerShell is quite easy in Windows 8 or higher: the Set-NetConnectionProfile command is available to do just that. However, in Windows 7 this is not so easy. Even though PowerShell 4 was installed, the command was absent. So I decided to create my own functions to facilitate this, based on this script by Microsoft: LINK. This script utilizes the Network List Manager to make the change. 

I created two functions named after the ones in Windows 8 and higher:

  • Get-NetConnectionProfile
  • Set-NetConnectionProfile

Here are some examples of how to use these (also included in the help):

# This will get the category for all network connections:
PS\> Get-NetConnectionProfile

IsConnectedToInternet : False
Category              : Public
Description           : Unknown network
Name                  : Unknown network
IsConnected           : True

IsConnectedToInternet : True
Category              : Domain
Description           : DOMAIN.LOCAL
Name                  : DOMAIN
IsConnected           : True

# This will get the category for all public network connections:
PS\> Get-NetConnectionProfile -NetworkCategory Public

IsConnectedToInternet : False
Category              : Public
Description           : Unknown network
Name                  : Unknown network
IsConnected           : True

# This sets the network category of the 'LAN1' connection to Private:
PS\> Set-NetConnectionProfile -Name 'LAN1' -NetworkCategory Private

IsConnectedToInternet : True
Category              : Private
Description           : LAN1
Name                  : LAN1
IsConnected           : True

# This sets the network category for all Public connections to Private
PS\> Get-NetConnectionProfile -NetworkCategory Public | Set-NetConnectionProfile -NetworkCategory Private

IsConnectedToInternet : False
Category              : Private
Description           : Unknown network
Name                  : Unknown network
IsConnected           : True

You can download or view the functions here: LINK

Hope it helps!

Michaja van der Zouwen

Is an all-round IT engineer with special skills in Microsoft, Citrix, RES and VMware products. Loves a challenge in his work and has taught himself scripts. Initially batch scripts, and later PowerShell. This helps him to automate processes and procedures, and to develop his own management tools which can be used every day.

Core qualities
Team player, enthusiastic, eager to learn, sociable, positive

Hobbies
Football, playing music, watching movies and series

Job description
Technical Specialist