Skip to content

Instantly share code, notes, and snippets.



Last active Jul 17, 2020
What would you like to do?
$RegUninstallPaths = @(
$VersionsToKeep = @('Java 8 Update 261')
Get-WmiObject Win32_Process | Where {$_.ExecutablePath -like '*Program FilesJava*'} |
Select @{n='Name';e={$_.Name.Split('.')[0]}} | Stop-Process -Force
get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue
$UninstallSearchFilter = { ($_.GetValue('DisplayName') -like '*Java*') -and
(($_.GetValue('Publisher') -eq 'Oracle') -or
($_.GetValue('Publisher') -eq 'Sun Microsystems, Inc.')) -and
($VersionsToKeep -notcontains $_.GetValue('DisplayName'))}
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}
write-host "yes"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
$ClassesRootPath = “HKCR:\Installer\Products”
Get-ChildItem $ClassesRootPath |
Where { ($_.GetValue('ProductName') -notlike '*Java*8*')} |
Foreach {Remove-Item $_.PsPath -Force -Recurse}
$JavaSoftPath = 'HKLM:\SOFTWARE\JavaSoft'
if (Test-Path $JavaSoftPath) {
Remove-Item $JavaSoftPath -Force -Recurse
if ($env:ProgramfilesJava) {
Remove-Item $env:ProgramfilesJava -Force -Recurse
else {
Write-Host "not installed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment