Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $RegUninstallPaths = @(
- 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
- 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
- $VersionsToKeep = @('Java 7 Update 40','Java 7 Update 40 (64-bit)','Java 8 Update 25','Java 8 Update 25 (64-bit)')
- #Kill anything that is running the jre executable
- Get-WmiObject Win32_Process | Where {$_.ExecutablePath -like '*Program Files*\Java\*'} |
- Select @{n='Name';e={$_.Name.Split('.')[0]}} | Stop-Process -Force
- #Kill IE, kill all of the IEs, they're as bad as lawyers
- get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue
- #Filter results from RegUninstallPaths to just Java entries by specified Publishers
- $UninstallSearchFilter = { ($_.GetValue('DisplayName') -like '*Java*') -and
- (($_.GetValue('Publisher') -eq 'Oracle') -or
- ($_.GetValue('Publisher') -eq 'Sun Microsystems, Inc.')) -and
- (Foreach{$VersionsToKeep -notcontains $_.GetValue('DisplayName')})}
- #Uninstall filtered results
- foreach ($Path in $RegUninstallPaths) {
- if (Test-Path $Path) {
- Get-ChildItem $Path | Where $UninstallSearchFilter |
- Foreach { Start-Process 'C:\Windows\System32\msiexec.exe' "/x $($_.PSChildName) /qn" -Wait}
- }
- }
- #Script by Phillip Sugg 10/16/2014
- #We would like you to know that those responsible for the comments, have just been sacked
Advertisement
Add Comment
Please, Sign In to add comment