Skip to content

Instantly share code, notes, and snippets.

@jfrantz1-r7
Last active July 17, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfrantz1-r7/2caf101065cd2aa2d94d0c6ebee55990 to your computer and use it in GitHub Desktop.
Save jfrantz1-r7/2caf101065cd2aa2d94d0c6ebee55990 to your computer and use it in GitHub Desktop.
$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