Reputation: 155
I'm trying to build do the PowerShell equivalent of the following VBScript code:
' get the version detail
wscript.echo CreateObject("WindowsInstaller.Installer").ProductInfo("{D7A3E989-A6F2-4CD3-A42D-EFC45029C282}", "VersionString")
Closest I can come up with is just boolean testing based on ProductCode
(New-Object -ComObject WindowsInstaller.Installer).GetType().InvokeMember('Products', [System.Reflection.BindingFlags]::GetProperty, $null, $(New-Object -ComObject WindowsInstaller.Installer), $null) -contains '{D7A3E989-A6F2-4CD3-A42D-EFC45029C282}'
Just looking for a quick way to confirm whether Product X is installed and pull relevant details like version.
Is there an non-complex way of accomplishing the VBScript equivalent in PowerShell?
Upvotes: 0
Views: 702
Reputation: 159
Translating VBScript code for WindowsInstaller to PowerShell is fairly straightforward, most examples around the web make it unnecessarily complicated.
The VBScript
' get the version detail
wscript.echo CreateObject("WindowsInstaller.Installer").ProductInfo("{D7A3E989-A6F2-4CD3-A42D-EFC45029C282}", "VersionString")
becomes
(New-Object -ComObject WindowsInstaller.Installer).ProductInfo("{D7A3E989-A6F2-4CD3-A42D-EFC45029C282}, "VersionString")
Upvotes: 1
Reputation: 36332
You could run a WMI query against Win32_Product like:
gwmi -class Win32_Product -filter 'IdentifyingNumber = "{D7A3E989-A6F2-4CD3-A42D-EFC45029C282}"'
Since the IdentifyingNumber should be a unique identifier I would suggest piping it to |%{$_;break}
so that as soon as it finds a result it stops looking.
gwmi -class Win32_Product -filter 'IdentifyingNumber = "{D7A3E989-A6F2-4CD3-A42D-EFC45029C282}"'|%{$_;break}
Upvotes: 0