0

The issue I'm having right now is that when I go to run the code through PowerShell, it is changing the value of the uninstall string and adding the variable name before it. The result i'm hoping for is this.

MsiExec.exe /X{2C5B24AD-9F13-52A1-KA2N-8K4A41DC9L4G}

But the result I'm getting from the variable after replacing the /I with an /X and doing .Trim() is the following:

@{UninstallString=/X{2C5B24AD-9F13-52A1-KA2N-8K4A41DC9L4G}}

So I was wondering if you guys would be able to tell me from my code below where I'm going wrong.

I have to replace the /I with /X, because the uninstall string first comes back like this MsiExec.exe /I{2C5B24AD-9F13-52A1-KA2N-8K4A41DC9L4G}, and I'm trying to uninstall, not install.

if ($Uninstall_str) {
    #run uninstall here
    try {
        $Uninstall_str = $Uninstall_str -replace 'MsiExec.exe /I', '/X'
        $Uninstall_str = $Uninstall_str.Trim()
        Start-Process "msiexec.exe" -Arg "$Uninstall_str /qb" -Wait
    } catch {
        Write-Output $_.Exception.Message
        Write-Output $_.Exception.ItemName
        Write-Warning "Error unintalling."
    }
}

2 Answers 2

1

You didn't expand the UninstallString value when reading it from the registry. Your code for doing that probably looks somewhat like this:

$Uninstall_str = Get-ItemProperty 'HKLM:\...\Uninstall\Something' |
                 Select-Object UninstallString

Replace that with

$Uninstall_str = Get-ItemProperty 'HKLM:\...\Uninstall\Something' |
                 Select-Object -Expand UninstallString

and the problem will disappear.

Sign up to request clarification or add additional context in comments.

Comments

0

To get rid of the @{uninstallstring all I needed to do was specify what I was trimming on this line

$Uninstall_str = $Uninstall_str.Trim()

So that line changed to the following to receive the results I was looking for.

$Uninstall_str = $Uninstall_str.Trim("@{UninstallString=")

1 Comment

That would only remove @{UninstallString= from the beginning of the string, but leave a spurious trailing } at the end. Don't do that. Fix the root cause of the issue instead, as outlined in my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.