question

BelgianMalinois avatar image
0 Votes"
BelgianMalinois asked LimitlessTechnology-2700 answered

Replacing REG_EXPAND_SZ Registry text

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaveKwas avatar image
0 Votes"
DaveKwas answered

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 :)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

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://docs.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--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.