dekyos

Java Removal Tool

Oct 17th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $RegUninstallPaths = @(
  2.     'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
  3.     'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
  4. $VersionsToKeep = @('Java 7 Update 40','Java 7 Update 40 (64-bit)','Java 8 Update 25','Java 8 Update 25 (64-bit)')
  5.  
  6. #Kill anything that is running the jre executable
  7. Get-WmiObject Win32_Process | Where {$_.ExecutablePath -like '*Program Files*\Java\*'} |  
  8.     Select @{n='Name';e={$_.Name.Split('.')[0]}} | Stop-Process -Force
  9. #Kill IE, kill all of the IEs, they're as bad as lawyers
  10. get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue
  11.  
  12. #Filter results from RegUninstallPaths to just Java entries by specified Publishers
  13. $UninstallSearchFilter = { ($_.GetValue('DisplayName') -like '*Java*') -and  
  14.     (($_.GetValue('Publisher') -eq 'Oracle') -or
  15.     ($_.GetValue('Publisher') -eq 'Sun Microsystems, Inc.')) -and
  16.     (Foreach{$VersionsToKeep -notcontains $_.GetValue('DisplayName')})}  
  17.    
  18. #Uninstall filtered results
  19. foreach ($Path in $RegUninstallPaths) {
  20.     if (Test-Path $Path) {
  21.         Get-ChildItem $Path | Where $UninstallSearchFilter |  
  22.         Foreach { Start-Process 'C:\Windows\System32\msiexec.exe' "/x $($_.PSChildName) /qn" -Wait}
  23.     }
  24. }
  25.  
  26. #Script by Phillip Sugg 10/16/2014
  27. #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