Created
February 27, 2018 21:50
-
-
Save zloeber/56c2a127583263136abebfdfcfe5428a to your computer and use it in GitHub Desktop.
PowerShell: Uninstall App or Exe via PackageManagement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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