使用PowerShell搜索和替换注册表项值

时间:2012-11-02 13:43:02

标签: powershell registry replace

我正在尝试更新一组注册表项,需要使用基于旧值的新值更新一组属性。

我尝试使用以下内容:

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

但是这会将uri属性的值设置为:{ $_.Value -Replace ".mydomain.com/", ".mynewdomain.com/" }

我试过了:

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

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

但这清除了价值。

我希望使用尽可能少的行更新多个键中的多个注册表值。我已经通过导出注册表,使用记事本来搜索和替换,然后重新导入注册表项,但这感觉就像作弊。我真的想知道如何使用Powershell实现这一目标。

我尝试过的其他内容:$(...)(...),省略了您为其命名的-Value选项:S。

我尝试将$_.Value替换为$_.Uri$_,但也无效。

问题现已解决,答案用于提供有关how to update your TFS project collection settings for the new Team Foundation Services的指导。

1 个答案:

答案 0 :(得分:3)

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