1

I'm trying to update a set of registry keys, a set of properties need to be updated with a new value based on the old value.

I tried using the following:

 Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri 
      | set-itemproperty -Path { $_.PSPath } Uri -Value { $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }

But that sets the value of the uri property to: { $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }

I tried:

 Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri 
      | set-itemproperty -Path { $_.PSPath } Uri -Value ${ $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }

And

 Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri 
      | set-itemproperty -Path { $_.PSPath } Uri -Value ( $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" )

But that clears the value.

I want to update multiple registry values in multiple keys with as few lines as possible. I already got it working by exporting the registry, use notepad to search and replace and then re-import the registry entries, but that felt like cheating. I really want to know how I can achieve this using Powershell.

Other things I've tried: $(...), (...), omitting the -Value option you name it :S.

I tried replacing $_.Value with $_.Uri and $_, didn't work either.

1 Answer 1

1
 Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri | %{set-itemproperty -Path $_.PSPath Uri -Value ( $_.Uri -Replace ".mydomain.com/", ".mynewdomain.com/" )}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.