Created
September 6, 2013 10:44
-
-
Save pekkavaa/6462235 to your computer and use it in GitHub Desktop.
Uninstalls the Windows applications that match the words defined by user.
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
<# | |
.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