Advertisement
Guest User

Java Fucker

a guest
Apr 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Java Cleanup x86
  2. ### This script will identify the latest version of Java and Rustle Jimmies with all prior versions.
  3.      
  4. # Search registry for Java uninstall keys.
  5. $findJava = GCI -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall | `
  6. Get-Itemproperty | Select Displayname,UninstallString,DisplayVersion | `
  7. where {$_.displayname -match 'Java [0-9]+ Update'}
  8.  
  9. # Find latest Java Version number.
  10. $latestJava = $findJava | Sort-Object -Property DisplayVersion | Select -ExpandProperty Displayversion -First 1
  11.  
  12. # Filter out latest version and build list of versions to uninstall from registry.
  13. $uninstallJava = $findJava | where {$_.displayversion -ne $latestJava}
  14.  
  15. # For each old version use uninstall string from registry and run as command to uninstall.
  16. if ($uninstallJava) {
  17.     $uninstallJava | ForEach-Object {
  18.         $uninstallString = $_ | select -ExpandProperty UninstallString
  19.         & cmd /c $uninstallString /quiet
  20.         }
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement