Last active
July 17, 2020 12:58
-
-
Save jfrantz1-r7/2caf101065cd2aa2d94d0c6ebee55990 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$RegUninstallPaths = @( | |
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', | |
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall') | |
$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