Skip to content

Instantly share code, notes, and snippets.

@pekkavaa
Created September 6, 2013 10:44
Show Gist options
  • Save pekkavaa/6462235 to your computer and use it in GitHub Desktop.
Save pekkavaa/6462235 to your computer and use it in GitHub Desktop.
Uninstalls the Windows applications that match the words defined by user.
<#
.SYNOPSIS
Uninstalls all unwanted programs listed in the $programNames array.
#>
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
Write-Warning "Please run this script as an Administartor. Aborting..."
break
}
$programNames = @("adobe reader", "DeskUpdate", "eBay", "Workplace Protect")
Write-Output "Removing programs with the following keywords in name: $programNames"
$installedPrograms = Get-WmiObject -Class Win32_Product
foreach ($program in $installedPrograms) {
foreach ($target in $programNames) {
$programName = $program.name.ToLower()
$targetName = $target.ToLower()
if ($programName.Contains($targetName)) {
$GUID = $program.IdentifyingNumber
$programFullName = $program.name
$arguments = "/x $GUID /qb /quiet /norestart"
Write-Output "Uninstalling $programFullName $GUID"
Start-Process -Wait -FilePath "msiexec" $arguments
}
}
}
$date = Get-Date
Write-Output "Done at $date."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment