Replacing REG_EXPAND_SZ Registry text

Belgian Malinois 461 Reputation points
2022-05-18T18:37:51.423+00:00

Just found out that one of our custom packages has multiple versions and the wrong uninstall key
UninstallString. REG_EXPAND_SZ MsiExec.exe /I(xxxxxxx-....}
How can I replace the /I with an /X using this script?

Find CalcSet installed and remove

$CalcSet = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  |
    Get-ItemProperty |
        Where-Object {$_.DisplayName -Match “CalcSet" } |
            Select-Object -Property DisplayName, UninstallString
           $CalcSet
  ForEach ($ver in $CalcSet) {
 
    If ($ver.UninstallString) {
 
        New-Item -Path c:\Source\CalcSet.txt -ItemType File -force
        $uninst = $ver.UninstallString
        & cmd /c $uninst /quiet /norestart

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. DaveK 1,871 Reputation points
    2022-05-19T19:33:06.683+00:00

    Hi, you should get away with doing a simple replace to give you the uninstall command your after.

    $uninst = $ver.UninstallString.Replace("/I","/X")
    

    I'd recommend posting code using the 'Code Sample' button as it helps other help you by being a little more readable :)

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,926 Reputation points
    2022-05-23T09:45:30.657+00:00

    Hello BelgianMalinois,

    My recommendation would be to add it into the next line using /uninstall (equivalent to /x)

    & cmd /c $uninst /quiet /norestart /uninstall <Package.msi|ProductCode>

    Reference:
    https://learn.microsoft.com/en-us/windows/win32/msi/standard-installer-command-line-options#uninstall-product

    ----------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.