Replacing registry substring

Hi,

I am trying finding all value v1 by v2 in the registry.

1. Running

$x=Get-ChildItem Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | foreach { Get-ItemProperty $_.PSPath } | Sort-Object Pschildname | Where-object pschildname -like "!test_ANv1*"

2. And I get

DisplayName     : !test_ANv1
DisplayVersion  : 2005 (v1)
InstallDate     : 2015-03-17
Language        : Fr
Publisher       : xxx
UninstallString : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionPolicy bypass -noexit -file "C:\Program 
                  Files\xxx\test_ANv1\test_ANv1_DesInstMan.ps1"
UninstallPath   : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionPolicy bypass -noexit -file "C:\Program 
                  Files\xxx\test_ANv1\test_ANv1_DesInstMan.ps1"
PSPath          : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\test_ANv1
PSParentPath    : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
PSChildName     : !test_ANv1
PSProvider      : Microsoft.PowerShell.Core\Registry


Not I need to replace all v1 by v2. Not the whole string just the v1 to v2 part.

3. I did try

$newValue = $x -replace "v1", "v2"

The replacement has worked. But I lost the format.

@{DisplayName=!test_ANv2; DisplayVersion=2005 (v2); InstallDate=2015-03-17; Language=Fr; Publisher=xxx; UninstallString=C:\Windows\System
32\WindowsPowerShell\v2.0\powershell.exe -executionPolicy bypass -noexit -file "C:\Program Files\xxx\test_ANv2\test_ANv2
_DesInstMan.ps1"; UninstallPath=C:\Windows\System32\WindowsPowerShell\v2.0\powershell.exe -executionPolicy bypass -noexit -file "C:\Program Files\xxx
\test_ANv2\test_ANv2_DesInstMan.ps1"; NoModify=1; NoRepair=0; NoRemove=0; InstalledConf=CARRA; PSPath=Microsoft.Po
werShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\!test_ANv2; PSParentPath=Microsoft.PowerShell.Core
\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall; PSChildName=!test_ANv2; PSProvider=Microsoft.PowerShell.Core\R
egistry}

How may I overwrite the actuals registry key by using those values?

March 27th, 2015 11:09pm

You are trying to make replacements in every key in the installer database.  Why?

You cannot change things in the installer database as it is owned and maintained by the installer.

Why do you think you need to do this?

Free Windows Admin Tool Kit Click here and download it now
March 28th, 2015 1:03am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics