Changing the network profile in Windows
·205 words·1 min
Sometimes it happens that the network profile of a connection in Windows is incorrectly categorised. Sometimes such an event happens out of the blue, even. This can be fixed by changing the value of the value of the Category-key of the network profile in the registry, which can be found here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\
There’s a sub-key for each network listed.
The following script can be used to change the category of the active network connection:
#Requires -Version 3.0
# Set-NetworkConnectionCategory.ps1
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, HelpMessage='The category to set the network-connection to (Public, Private or Domain)')]
[ValidateSet('Public','Private','Domain')]
$ConnectionCategory
)
Add-Type -Language CSharp -TypeDefinition @"
public enum ConnectionCategory{
Public,
Private,
Domain
}
"@
$ConnectedNetwork = (Get-NetConnectionProfile).Name
$NetworkConnectionProfiles = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\' | select -expand Name
$NetworkConnectionProfiles | Foreach-Object {
$key = $_ -replace "^HKEY_LOCAL_MACHINE", "HKLM:"
# $keyToChange = (Get-ItemProperty $key).PSObject.Properties | Where-Object { $_.Value -match $ConnectedNetwork }
# # $keyToChange | ForEach-Object { Set-ItemProperty -Path $key -Name $_.Name -Value ($_.Value -replace $pathToReplace,$newPath) -Verbose }
if ((Get-ItemProperty $key).PSObject.Properties["ProfileName"].Value -eq $ConnectedNetwork) {
Write-Output "You are about to set the connectioncategory for '$ConnectedNetwork' to '$ConnectionCategory'."
Set-ItemProperty -Path $key -Name "Category" -Value ([int]([ConnectionCategory]::$ConnectionCategory)) -Verbose -Confirm:$true
break;
}
}
UPDATE: Or, you could just use:
Set-NetConnectionProfile -NetworkCategory [DomainAuthenticated | Private | Public]
…