1

I started with this, on a recommendation from a friend

Get-WmiObject win32_product | ft name, version

But then I found this, which gives me pause. A little research led me to this

wmic product where "Name='Revit 2018'" get name,version

Which works as far as the data gathered. And yes, I am looking for a different program in this example. in any case, once I had good info using WMIC I tried to get the data into a variable so I could get just the version number, but the data formatting is something I have never seen before. I was hoping for a simple solution, like

$object = wmic product where "Name='Revit 2018'" get name,version
$object.version

But only the result is an array with 6 items, and only one seems to be the actual data line, and that's a single line, not two properties. And, I really wonder if an old command line utility is the right answer here. If it really is the best way to do this, is there a trick to converting the raw data to something more, PowerShelly? And if it's not the best way to get this info, what is? Is that scary link real, or is Get-WmiObject win32_product actually safe? And if so, is there a way to filter on a specific name, to speed things up? And indeed, Get-WmiObject doesn't work as I was expecting, as

$object = Get-WmiObject win32_product | ft name, version
foreach ($item in $object) {
    Write-Host "$($item.version)"
}

Doesn't work as expected at all.

EDIT: This seems to be working as expected, which is progress.

$version = (Get-WmiObject win32_product -filter:"Name = 'Revit 2018'" | Select-Object -property:*).version
Write-Host "$version!"

I guess the question is really, is this a safe and consistent approach, or is there a better one?

Gordon
  • 6,257
  • 6
  • 36
  • 89
  • I've used `win32_product` multiple times, and the results have always been... inconsistent at best. It sometimes works and sometimes doesn't. Never found a better method – cet51 Jun 04 '18 at 20:52
  • `wmic product` resolves to query `win32_product` in the end, so won't make a difference. An alternative approach is [to query the registry](https://stackoverflow.com/a/25268564/712649) – Mathias R. Jessen Jun 04 '18 at 21:30

1 Answers1

1

Why not use the registry?

Set-Location HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
$app = Get-ChildItem | Where-Object { $_.GetValue("DisplayName") -match 'YourSoftware' }

$app.GetValue("DisplayVersion")

Or

Set-Location HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
$apps = Get-ChildItem
foreach ($app in $apps) {
  $app.GetValue("DisplayName","DisplayVersion")
}

Note: You'll also need to check the SysWow64 registry location as well

HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ 

Note: Not all items will have a display version in which case you always have the option of looking in the installation directory for the executable itself, which should have a version on it.

  • I guess I don't trust that the vendor (Autodesk in this case) is providing accurate information. Then again, WMI may very well just be gathering the same (suspect) info. Time to test a bunch of things and see if I can get consistent results. – Gordon Jun 04 '18 at 22:07
  • @Gordon acquiring version information has always been this way. If you're looking for consistency using only one approach; either WMI, or the registry then you're going to be sorely disappointed I'm sorry to say. I think the *most* consistent approach is to get the version info off the executables themselves. (Get-Item .\prog.exe).psextended.VersionInfo.ProductVersion – Repeat Daily Jun 05 '18 at 01:10