PowerShell command to set all network connection profiles to Private

What is the correct syntax of the PowerShell command to set all network connections as private?

For example I currently run the PowerShell command Get-NetConnectionProfile. This command lists my network connection profiles and tells me if they are public, private, or domain authenticated.

Then I run the command Set-NetConnectionProfile  -InterfaceIndex 2 -NetworkCategory Private to set Network connection profile 2 to private.

What is the powershell command that I can run that will set all Network Connection profiles to private using a single PowerShell command?

I have tried using wildcards such as the asterisk (*) symbol instead of typing in a number (such as 2) but this doesn't work.

What is the correct syntax of the PowerShell command that will set all network connections to private?
IT GuyNetwork EngineerAsked:
Who is Participating?
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
The interfaceindex accepts pipeline input by parameter name.  It worked for me, but if you want an alternate way then you can use the code below.

Get-NetConnectionProfile | % { Set-NetConnectionProfile -InterfaceIndex $_.InterfaceIndex -NetworkCategory Private }

Open in new window

0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
You should be able to do this with something like

get-netconnectionprofile | set-netconnectionprofile -NetworkCategory private

Open in new window

0
 
Hello ThereSystem AdministratorCommented:
I am not aware that something like this exists. You have to specify Interface Index.
0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
The interfaceindex accepts pipeline input by parameter name.
0
 
Hello ThereSystem AdministratorCommented:
But you can use a PS1 script:
Get-NetConnectionProfile |
  Where{ $_.NetWorkCategory -ne 'Private'} |
  ForEach {
    $_
    $_|Set-NetConnectionProfile -NetWorkCategory Private -Confirm
  }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.