Skip to content

Instantly share code, notes, and snippets.

@istairbn
Created March 22, 2017 13:29
Show Gist options
  • Save istairbn/78552e41d0cc09903c0ed3c2b93c1762 to your computer and use it in GitHub Desktop.
Save istairbn/78552e41d0cc09903c0ed3c2b93c1762 to your computer and use it in GitHub Desktop.
PowerShell funciton to uninstall a list of programs by display name
Function Uninstall-Program{
<#
.SYNOPSIS
Uninstalls Windows Programs using display name
.Parameter DisplayName
String match for the programs to uninstall. Accepts pipeline input
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[String[]]
$DisplayName
)
$RegEntries = @()
ForEach($Name in $DisplayName){
$RegEntries += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.DisplayName -match $Name }
}
ForEach($Entry in $RegEntries){
$Entry.DisplayName
$UninstallCommand = "/X `"$($Entry.PSChildName)`" /q"
Start-Process msiexec.exe -NoNewWindow -Wait -ArgumentList $UninstallCommand
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment