Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted
 Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri | %{set-itemproperty -Path $_.PSPath Uri -Value ( $_.Uri -Replace ".mydomain.com/", ".mynewdomain.com/" )}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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