sebbu

Detect Installed Java Versions

Sep 21st, 2024 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env pwsh
  2. # Import-WinModule Microsoft.PowerShell.Management
  3. $UninstallPath1 = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
  4. $UninstallPath2 = 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
  5. $UninstallPath3 = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
  6. $UninstallPath4 = 'HKCU:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
  7. $Uninstalls = (Get-ItemProperty $UninstallPath1\*) + (Get-ItemProperty $UninstallPath2\*) + (Get-ItemProperty $UninstallPath3\*) + (Get-ItemProperty $UninstallPath4\*)
  8. $Uninstalls | Where-Object { ($_.DisplayName -Like '*java*') -or ($_.DisplayName -Like '*jdk*') } | Select-Object -Property DisplayName, DisplayVersion, PSPath | Sort-Object DisplayName, DisplayVersion | Format-Table -Wrap
  9.  
Add Comment
Please, Sign In to add comment