WMI instead of WMIC command to find application version?
I'm using wmic to find the current version of an in-house application. My command looks like this:
wmic product where "name='Application Name'" get version
I've never used wmi, but I've read about people saying it's easier to use than wmic. I think my use is a pretty simple one, but how would I use wmi for this, and would it be faster than wmic? (wmic runs very slowly for me)
PowerShell
Get-WMIObject -Query "SELECT Version FROM Win32_Product WHERE Name='SomeName'"
I've read bad things about using Win32_Product
. I don't know the details about it, so maybe it's fine in this case, but I ended up going with the following after reading this blog and asking this question:
$regpath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$version = Get-ItemProperty "$regpath\*" |
Where-Object { $_.DisplayName -eq 'Application Name' } |
Select-Object -Expand DisplayVersion
To emulate the wmic command you posted using WMI, open a PowerShell prompt and input:
Get-WmiObject -Class "Win32_Product" | Where-Object { $_.Name -eq "Application Name" } | select Name,Version
You can use { $_.Name -like "*application*" }
for better matching, if needed.
This can also be run against remote machines and/or using different credentials by adding the -ComputerName
and -Credential
parameters.