Skip to content

Instantly share code, notes, and snippets.

@wise-io
Last active May 30, 2022 11:25
Show Gist options
  • Save wise-io/d3d4c54dd3c6faceab1bf4a4982767f8 to your computer and use it in GitHub Desktop.
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.
# 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