Change "Unidentified networks" to "private" in powershell
I would like to change the connection type for "Unidentified" networks to Private in Windows using Powershell. Ideally this should work in Win 8 and 10.
An alternative solution would be to make windows identify this network and then I can set the location to private. It is a VirtualBox host only network with a Linux host.
I can use the UI to do this with the following steps:
- Open Group policy editor eg (start -> gpedit.msc)
- Computer Configuration -> Windows Settings -> Security Settings -> Network List Manager Policies
- Where it says "Unidentified Networks", Right click -> Properties
- Change "Location type" to Private
I have googled and tried:
$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$connections = $networkListManager.GetNetworkConnections()
$connections |foreach {
$_.GetNetwork().SetCategory(1)
}
but this does not survive a reboot.
I wrote a script last year and put it on GitHub. It does exactly what you want:
Set-NetworkProfileCategory.ps1 -Name 'Unidentified network' -private
I haven't tested it for a while, but you can try.