I'm trying to change the location setting of a network to Private regardless of whether it's connected or not, but the Get/Set-NetConnectionProfile cmdlet doesn't work for this function unless you're currently connected to the network you're trying to change.
Currently I'm able to search and list the GUIDs and all subkeys of the existing networks with
Get-ChildItem -path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles' -Recurse |
Where-Object { $_.GetValueNames() -match 'ProfileName' }
but I'm not sure how to chain that into just returning the Key with the ProfileName subkey = "foo". I plan to save the path to a variable and then change the "Category" subkey to private. I'm just not sure how to bridge the two pieces and just get the key/path of the network profile I want.
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles' |
Where-Object { $_.GetValue('ProfileName') -eq 'foo' }
$_.GetValue('ProfileName')
looks for a value named ProfileName
on each Microsoft.Win32.RegistryKey
instance returned by the Get-ChildItem
call and compares its data to string 'foo'
; note that if a child key should happen not to have a ProfileName
value, the .GetValue()
call would quietly return nothing ($null
).
As you later pointed out, piping to Set-ItemProperty
allows modification of the values of the key returned; e.g.:
... | Set-ItemProperty -Name Category -Value 1
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments