2
  1. Get-Package "Google Chrome" | % { & ($_.Meta.Attributes["UninstallString"] -replace '"') /S

This command uninstalls other software except Google chrome , provider is programs. I have tried many things but this does not work. Please help

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Swati
  • 21
  • 1
  • What do you mean by, "*without manual acceptance*"? Do you mean silently? I believe you're calling the wrong string. Most programs will have a *quietuninstallstring*. – Abraham Zinala Jul 24 '21 at 20:53
  • Good points, @AbrahamZinala, though I wouldn't say that _most_ have a `QuietUninstallString`; I'd say that not only _some_ even have an `UninstallString`, and among those only some have a `QuietUninstallString`. Swati is trying to achieve silent uninstallation with `/S`, but the command wouldn't work syntactically - and, above all, it seems that (a) Google Chrome doesn't even have an `UninstallString` value, and (b) piping to `Uninstall-Package` instead is a much simpler way to uninstall. – mklement0 Jul 24 '21 at 21:33
  • 1
    Uninstall-package is not working for programs based provider. It only works for MSI based softwares. – Swati Jul 24 '21 at 21:50
  • In registry key there uninstall string of Google Chrome, I tried invoke-expression as well but that also gives error for missing positional parameter for acceptance. – Swati Jul 24 '21 at 21:52
  • This command works , only thing is , i want to push this command remotely where it should not ask " Are you sure you want to uninstall Google Chrome , prompts for input Uninstall and Cancel". I am looking for unattended uninstallation where , where it accepts automatically for uninstallation . Can you also help me with invoke-expression , how to use command and arguments , The uninstall string that is supposed to be used is --- "C:\Program Files\Google\Chrome\Application\92.0.4515.107\Installer\setup.exe" --uninstall --channel=stable --system-level --verbose-logging – Swati Jul 26 '21 at 05:48

1 Answers1

3

You say that your Google Chrome installation was performed via the Programs package-management provider, rather than via the msi provider (for the latter, see the bottom section).

Assuming that $_.Meta.Attributes["UninstallString"] has a value, it contains a string that contains a no-shell / for-cmd.exe command line, which often will not work when executed directly from PowerShell with Invoke-Expression, because PowerShell has more metacharacters than cmd.exe that require quoting, notably { and }, as used in GUIDs.

  • More fundamentally, &, the call operator does not support executing whole command lines, it expects only the name or path of a command or executable, optionally followed by arguments.

In the simplest case, you can do the following:

Get-Package 'Google Chrome' | % { 
  cmd /c ($_.Meta.Attributes['UninstallString'] + ' /S')
}

For more information, see this answer.


IF your Google Chrome was installed via the msi package provider (verify with: (Get-Package 'Google Chrome').ProviderName):

Not all installed programs have an UninstallString attribute (and even fewer have a QuietUninstallString one), and an msi-provider-installed Google Chrome doesn't have one.

However, you should be able to pipe to Uninstall-Package for silent (unattended) uninstallation:

Get-Package 'Google Chrome' | Uninstall-Package
mklement0
  • 382,024
  • 64
  • 607
  • 775