I'm trying to uninstall Java using PowerShell using the code below. I want the powershell to look into both HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall* and HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall* and then uninstall.
For some reason, it only pulls from $source2 and not from $source. Can someone please assist me with what I'm missing here? I'd really appreciate it. $Source gets the value for Java 32-bit and $Source2 picks up the value for Java 64-bit.
$Source = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
$source2 = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*
$Uninstall = $Source | Where-Object {($_.Publisher -like '*Oracle*')-and ($_.DisplayName -like 'Java*')} | select UninstallString
$Uninstall = $Source2 | Where-Object {($_.Publisher -like '*Oracle*')-and ($_.DisplayName -like 'Java*')} | select UninstallString
$UninstallStrings = $Uninstall.UninstallString -replace "MsiExec.exe ","MsiExec.exe /qn " -replace "/I","/X"
ForEach($UninstallString in $UninstallStrings){& cmd /c "$UninstallString"}