2

I have the following PowerShell script, which I am using to get the uninstall string for Google Chrome, and then I want to uninstall it silently. Line 3 in the script will pop up the GUI uninstaller (so it seems like everything is correct thus far), but if I add "/qn" or "/quiet" to the argument list, the uninstall doesn't seem to run at all, even if I let it sit for a couple hours.

What am I missing?

    $AppName = "Google Chrome"
    $Chrome = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match $($AppName)}
    Start-Process -Wait -FilePath MsiExec.exe -Argumentlist "/X",$Chrome.UninstallString.TrimStart("MsiExec.exe /X")
TylerH
  • 20,799
  • 66
  • 75
  • 101
Andrew
  • 79
  • 2
  • 4
  • 11

2 Answers2

4

If it's an msi you can use uninstall-package:

get-package *chrome* | uninstall-package -whatif
js2010
  • 23,033
  • 6
  • 64
  • 66
0

instead of trying to use /X and remove /X and other things, try the following

# Get the key to uninstall
$chromeUninstall = $Chrome.Pspath.Split("\")[-1]

Start-Process -Wait -FilePath MsiExec.exe -Argumentlist "/X $ChromeUninstall /quiet /norestart"

or even simpler would be,

Start-Process -Wait cmd.exe -ArgumentList "/c msiexec /X $ChromeUninstall /quiet /norestart"

/c - Carries out the command specified by string and then terminates


Note

On my system I get two uninstall strings. You might want to think about looping or selecting first one in the list with the use of [0]

Jawad
  • 11,028
  • 3
  • 24
  • 37
  • Your first example throws a few errors. Using your second example looks like it starts a "Windows Installer" process in Task Manager, but still returns to the command prompt more or less right away, and doesn't seem to uninstall Chrome. I'm curious, what does the "/c" do? – Andrew Feb 14 '20 at 15:57
  • @Andrew Updated my answer. Instead of using UninstallString, use the PSPath to get the key to use for uninstall. – Jawad Feb 14 '20 at 16:03
  • No improvement, unfortunately. Same as before, it starts a Windows installer process and returns to the command prompt pretty much right away, but doesn't seem to do anything, even after waiting a while. – Andrew Feb 14 '20 at 19:04
  • Ok, I think admin rights had something to do with this, even though my username is in the local admin group on this PC. I simplified one of your suggestions to "cmd.exe /c $Chrome.UninstallString /Passive", and noticed a UAC prompt when it ran. I then changed /Passive to /qn and opened the Powershell ISE as admin, and it removed Chrome quickly and easily. Thanks again for the help! – Andrew Feb 14 '20 at 19:46