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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.