I wanted to start by saying i did read some other topics on this but at this point i still have to do it none the less (decision been made above my pay grade).
We are in the process of moving and testing out Azul java to see how well that works for us. Meantime I need to figure out how to script the uninstall of the all Oracle java (preferably I would have a script for JRE and another for JDK).
Currently how I have been removing java versions is by having a list of all jre versions doing msiexec /x "GUID of the java version" /qn but it is incredibly time consuming so I wanted to get those strings pragmatically.
Right now I run the following command:
Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like 'Java*'}
However, I am trying to find out how to automatically get the IdentifyNumber for every result as long as Vendor = Oracle Corporation and pipe it to the msiexec command to problematically remove them. Azul is installed on the same system as the command is being ran but is not showing up (which is good but just in case I wanted to have the vendor qualifier).
My question is: Can someone help me pipe the IdentifyNumber of the product into msiexec command assuming Vendor is Oracle Corporation
Thank you in advance.
Update 1: Following feedback from Drew and Ansgar
$Source = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
$Uninstall = $Source | Where-Object {($_.Publisher -like '*Oracle*')-and ($_.DisplayName -like 'Java*')} | select UninstallString
$UninstallString = $Uninstall.UninstallString
$UninstallSting | ForEach-Object{Invoke-Expression -ScriptBlock ($UninstallString)}
However, I cant seem to pipe the strings correctly as I keep getting:
Invoke-Command : Cannot convert 'System.Object[]' to the type 'System.Management.Automation.ScriptBlock' required by parameter 'ScriptBlock'. Specified method
is not supported.
At C:\Konstantin\Java\UninstallAllJava.ps1:8 char:62
+ ... ting | ForEach-Object{Invoke-Command -ScriptBlock ($UninstallString)}
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.InvokeCommandCommand
