title: Search and replace registry entry value using powershell
body: <p>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.</p>
  
  <p>I tried using the following:</p>
  
  <pre><code> Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri 
        | set-itemproperty -Path { $_.PSPath } Uri -Value { $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }
  </code></pre>
  
  <p>But that sets the value of the uri property to: <code>{ $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }</code></p>
  
  <p>I tried:</p>
  
  <pre><code> Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri 
        | set-itemproperty -Path { $_.PSPath } Uri -Value ${ $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }
  </code></pre>
  
  <p>And</p>
  
  <pre><code> Get-ItemProperty -Path HKCU:\Software\xxxxx\*.mydomain.com Uri 
        | set-itemproperty -Path { $_.PSPath } Uri -Value ( $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" )
  </code></pre>
  
  <p>But that clears the value.</p>
  
  <p>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.</p>
  
  <p>Other things I've tried: <code>$(...)</code>, <code>(...)</code>, omitting the <code>-Value</code> option you name it :S.</p>
  
  <p>I tried replacing <code>$_.Value</code> with <code>$_.Uri</code> and <code>$_</code>, didn't work either.</p>
  
  <p>The problem is now resolved and the answer used to give guidance on <a href="http://blog.jessehouwing.nl/2012/11/updating-your-team-foundation-service.html" rel="nofollow">how to update your TFS project collection settings for the new Team Foundation Services</a>.</p>