Last active
May 30, 2022 11:25
-
-
Save wise-io/d3d4c54dd3c6faceab1bf4a4982767f8 to your computer and use it in GitHub Desktop.
PowerShell script to set the network category (type) to Public or Private.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sets current network category (type) to Public or Private. | |
# Should be run with Administrator privileges. | |
param ( | |
[Parameter (Mandatory = $true)] | |
[ValidateSet('Public', 'Private', IgnoreCase)] | |
[string]$Category # Desired Network Category | |
) | |
# Format parameter | |
$Category = (Get-Culture).TextInfo.ToTitleCase($Category) | |
# Get Current Network Profile | |
$CurrentNetwork = Get-NetConnectionProfile | |
# Set Network Category | |
try { | |
if ($CurrentNetwork.NetworkCategory -ne $Category) { | |
Set-NetConnectionProfile -Name $CurrentNetwork.Name -NetworkCategory $Category | |
Write-Output "Network category set to $Category." | |
} | |
else { | |
Write-Output "Network category was already set to $Category." | |
} | |
} | |
catch { | |
throw | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment