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