I recently found a script made by the almighty Johan Arwidmark, for those of you familiar with MDT. He suggests to use a com object based around WindowsInstaller.Installer. I made some modifications and turned it into a local Immy function called Detect-SoftwareWithCOM. Here’s the script itself:
param(
[Parameter(Mandatory=$false,Position=0)]
[String]$InstalledSoftware
)
Invoke-ImmyCommand {
$Installer = New-Object -ComObject WindowsInstaller.Installer
$InstallerProducts = $Installer.ProductsEx("", "", 7)
$InstalledProducts = ForEach($Product in $InstallerProducts){
[PSCustomObject]@{
Name = $Product.InstallProperty("InstalledProductName")
ProductCode = $Product.ProductCode()
LocalPackage = $Product.InstallProperty("LocalPackage")
VersionString = $Product.InstallProperty("VersionString")
VersionMajor = $Product.InstallProperty("VersionMajor")
VersionMinor = $Product.InstallProperty("VersionMinor")
ProductPath = $Product.InstallProperty("ProductName")
InstallSource = $Product.InstallProperty("InstallSource")
InstallDate = $Product.InstallProperty("InstallDate")
URLUpdateinfo = $Product.InstallProperty("URLUpdateInfo")
Transforms = $Product.InstallProperty("Transforms")
ProductIcon = $Product.InstallProperty("ProductIcon")
}
}
$InstalledProducts | Where-Object { $_.productpath -like "*$($using:InstalledSoftware)*" }
return
}
I’ve mentioned the negatives of using WMI with the Win32_Product class before, so here’s a bit of an alternative. Once I figure out how to utilize the detection to start an uninstall, I’ll add it here.
For more information here’s a couple resources about the problem WMI class:
Please Stop Using Win32_Product To Find Installed Software. Alternatives Inside! | xkln.net
and even Microsoft’s own documentation:
Win32_Product class (Windows) | Microsoft Learn