while silently reading here for half an eternity, now comes the point where I´d like to ask a question.
We have been carved out from a big company lately and one of the endless things we have to solve is caring for sw-licensing.
However in this process it turned out that oracle is not a software company having at least a slight interest in senseful co-existing but a plain mafia-gang. So after a few meetings with those self-righteous mobsters I just quitted and promised to wipe and extinct their SW from each server/client in order to not step in their criminal-licensing-traps. While we already got rid of all oracleDBs, oracle java is still a problem also because employees keep installing it here and there not caring for consequences. (worldwide ~7500clients azure-managed).
So I want to come up with an remediation script looking for oracle java periodicly and deleting it.
While detection is working I cannot figure out why remediation is not working; So after two days of struggling around (I´m quite new to remediation methods and not a pro in powershell ) I´d like to know how you would do it:
Detection (works)
$MSICode = gwmi Win32_Product -filter "name like 'Java%' AND vendor like 'Oracle%'" | select IdentifyingNumber
if ($MSICode -eq $null){
Write-Host "oracle java installations not found"
Exit 0
}else{
Write-Host "oracle java installations found"
Exit 1
}
Remediation (Always prompts me with msiexec error asking for the right syntax while "write-Output $Deinstallcommands" shows the right values
$MSICode = gwmi Win32_Product -filter "name like 'Java%' AND vendor like 'Oracle%'" | select IdentifyingNumber
# Variable "Deinstallcommands" bereinigt die MSICode Variable ( + silent deinstall ) sodass sie wie cmd ausgeführt werden kann.
$Deinstallcommands = $MSICode.IdentifyingNumber -replace "{","MsiExec.exe /x{"
# Alle Deinstallcommands ausführen
#write-Output $Deinstallcommands
ForEach($IdentifyingNumber in $Deinstallcommands) {& cmd /c "$Deinstallcommands"}
Looking forward to your replies
IdentifyingNumber
for each iteration.Get-WmiObject
, which is a more modern and PowerShell-native way of retrieving WMI information andSelect-Object -ExpandProperty IdentifyingNumber
to extract the IdentifyingNumber from the WMI query resu lt.I modified the loop to use each individual
IdentifyingNumber
in the uninstallation command and added/qn
to theMsiExec.exe
command for silent uninstallation (no user interface).