Skip to content

Instantly share code, notes, and snippets.

@zloeber
Created February 27, 2018 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zloeber/56c2a127583263136abebfdfcfe5428a to your computer and use it in GitHub Desktop.
Save zloeber/56c2a127583263136abebfdfcfe5428a to your computer and use it in GitHub Desktop.
PowerShell: Uninstall App or Exe via PackageManagement
Function Remove-InstalledApp ([string]$AppName) {
get-package $AppName -ErrorAction:SilentlyContinue | Foreach {
$app = $_
switch ($app.ProviderName) {
'msi' {
Write-Output "Uninstalling msi for $($app.Name)"
$app | Uninstall-Package
}
'PowerShellGet' {
Write-Output "Uninstalling PowerShellGet package for $($app.Name)"
$app | Uninstall-Package
}
'Programs' {
if ( $null -ne $app.metadata['UninstallString'] ) {
Write-Output "Found uninstall string for $($app.Name), calling it now..."
Invoke-Expression "& $($app.metadata['UninstallString'])"
}
}
Default {
Write-Output "Uncertain what we should do with package $($app.Name) (Provider = $($app.ProviderName))"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment