Slightly tricky registry manipulation?

Hi all, I have a situation where I need to update 1200+ registry values in two different hives, mostly in Classes\Root, on a farm of twenty servers, due to a badly coded 3rd-party app that I can’t get rid of. I could probably do this via GPO, but I’m trying to use this as an excuse to expand my PS toolbox. :slight_smile:

The only thing every value has in common is that the data contains the same text (a hard-coded server hostname IRL, represented by “Bogus Data” in the example below). Note that in this example I am only working with HKCU, for simplicity.

[HKEY_CURRENT_USER\Environment\BogusKey] @="Bogus Data lives here" "RealValue"="Valid Data"

[HKEY_CURRENT_USER\Environment\FakeKey]
@=“DO NOT EDIT”
“FakeValue”=“This is also Bogus Data”

I thought that the simplest approach would be to find the values with “Bogus Data” in them, get the value name and then feed that into a variable for Set-ItemProperty, to replace the data with “Valid Data”… I can get as far as isolating the keys that contain “Bogus Data”, but am stuck on how to get PS to either give me the value name or do the replace directly.

Below is the code I have worked up to this point, that just shows all values for the affected keys and proves I am correctly isolating the keys I want.

Any insights would be greatly appreciated!

$searchPath = "HKCU:\Environment\*"
$oldData       = "Bogus Data"
$newData     = "Valid Data"

Get-ChildItem -Path $searchPath |
  ForEach-Object {
    if ((Get-ItemProperty -path $_.PSPath) - match $oldData) {
      Get-ItemProperty -path $_.PSPath
    }
  }

I figure if I can get past this, then I should be able to use Split and Join to isolate the bit of text I need to update, and feed that back in.

$keys = get-itemproperty "HKCU:\Enviroment" - recursive | ?{$_.value -eq $oldData}

Foreach($key in $keys) {
set-itemproperty $key -Value $newData
}

I’m not on my pc but something like this maybe

Hi Mark,
Thanks! I did try something along those lines… putting this line inside my foreach loop does correctly update the data, for any single named Value:

Set-ItemProperty -Path $_.PSPath -name '(default)' -Value $newData

My problem is that I am not convinced that every instance of this data is in (default), and with 1200+ entries, I’m trying to come up with a solution that doesn’t mean I have to walk the registry and look at each of them to confirm that. Thus, hoping to find a way to get PS to reverse-engineer the call and say, “here’s a Value with your data in it, and this is what it’s named.”

Thanks for the response!