Find all java uninstall strings

Hello Powershell teams,

I am trying to pull all Java uninstall string from the Registry 32 and 64.

$Javauninstall = gci “HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall”, “HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” | 
foreach { gp $_.PSPath } | 
? { $_ -like “*Java*” -and $_.Publisher -like “*Oracle*” } | 
select UninstallString

And what is your question?

BTW: It would be considered to be polite and good style when you avoid using aliasses. It makes your code easier to read. :wink:
Thanks in advance. :+1:t4:
You may read more about that topic:

Thank you Olaf!
I was trying to pull the Java uninstall string from the registry to proceed an uninstallation of all Java app.
I think I figured it out.

$Javauninstall = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$uninstalllist = Get-ChildItem -Path $Javauninstall | foreach { gp $_.PSPath }  -ErrorAction SilentlyContinue | 
? { $_ -like “*Java*” -and $_.Publisher -like “*Oracle*” } | select UninstallString
if ($uninstalllist) {
$uninstalllist = $uninstalllist.UninstallString -Replace "msiexec.exe", "" -Replace "/I", "" -Replace "/X", ""
$uninstalllist = $uninstalllist.Trim()
Write "Uninstalling Java ..."
start-process "msiexec.exe" -arg "/X $uninstalllist  /qn /norestart" -Wait
}

… still a lot of room for improvement when it comes to readability and code formatting. But if it works it’s fine. :+1:t4: Well done.

That’s true. You are the master, and I can’t imagine how you feel when you see my script formatting. It is a mess. I will try to be better teach!
Thank you to point that out.

No, I’m not. :wink: I’m just to old and lazy to spend my time reading badly formatted code. :wink:

First of all it makes your life easier and only on top of that it is more polite to the people need to deal with your code. :wink:

Yes, I see. We don’t do the code for only ourselves. We should put in mind that someone else will use it too. So, it is good to follow a minimum formatting standard so they can understand it easily.

That’s what I meant. :+1:t4: :+1:t4: And if you review your own code in 6 month or more you are another person as well. :wink: … and I could imagine that you’ll like when your code code is easy to read and to understand and you don’t have to re-think how came to the code you wrote that time ago.

1 Like