Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.