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

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

我正在尝试更新一组注册表项,需要根据旧值将一组属性更新为新值。

我尝试使用以下方法:

 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$_也没有用。

答案1

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

相关内容