Replacing REG_EXPAND_SZ Registry text

Belgian Malinois 336 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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,361 questions
0 comments No comments
{count} votes

Accepted answer
  1. DaveK 1,846 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,351 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