Powershell - How to search for hashed registry key with known subkey name and value

Cory W

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.

mklement0
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.

edited at
0

Comments

0 comments
Login to comment

Related

how to filter name/value pairs under a registry key by name and value in PowerShell?

How to get the subkey from the key in the registry tree using NSIS?

how to get the data value of the registry value inside a key using powershell

How to convert Data Object { "key.subkey": "value" } to { "key" : "subkey": { "value" } } Javascript

How can I get and change the Value of the "(Standard)" key in the Registry with Powershell

Query a single registry subkey using PowerShell?

C# Registry Subkey dword value

Generate hashed name for SSH known_hosts

How to extract hive and registry name from registry key

How do search a value from multiple valueNames in registry key using vb.net

How to add a String Value/ Name Data pair in Windows Registry Editor key using C++ and Windows Registry API's

Powershell Registry Search & Edit

How to recover all the elements of a registry key? (last write time, type, value, name …) Is this the right method?

How to remove dictionary key with known value?

How to append a registry key value that has spaces in it?

How to read value of a registry key c#

How to extract path from registry key value?

php - how to merge key with subkey in one array

Checking if a value name for a key is present on the windows registry through batch file

Difference between hashed value, and key-value?

How to get value for key in array when the key is not known

How do I model a key/value for which the key is not known in Swagger

How to access value of nested dictionary with only subkey?

How can you SSH to an unknown host name with a known key?

How to update the folder name in InstallShield project for Registry section by Powershell?

How to edit a registry key for every profile, without knowing their name?

Powershell - Create Volatile Registry key?

Powershell a registry key via InTune

Powershell to find registry key and delete it

TOP Ranking

HotTag

Archive