Recently, I needed MC274503 to obtain the installedversion of Outlook 2016 for many workstations. Luckily, we can use WMI to obtain information about files on workstations including the version.

When I need to write a WMI query, I find if very helpful to start with WMI Explorer.

To use WMI Explorer, simply connect to a workstation, select the Namespace you’d like to query (Generally CIMV2), and write your WMI query. When you’re looking for specific information, it helps to first query all data (within reason), and then narrow it down to specifics. Below, shows a screenshot with the very query I used to complete my task.

First I selected the class I wanted to query data from. However, if we executed this query, it would attempt to return all data in this class. Which would include a result for everyfile on your local system. Too much data!

SELECT * FROM CIM_DataFile

Let’s scope our query by using the WHERE statement.

SELECT * FROM CIM_DataFile WHERE path='\\program files (x86)\microsoft office\office16\\'

This will bring back the files located in this directory. Files in sub-directories are not included. Each result is listed with all associated properties. Now I know exactly whatproperties I am able to gather.

I want to limit my query to one result. To do this, I will query a specific file name and a specific file extension. This ensures that it is only possible to get one result. You can onlyhave one file with the same name and extension in a directory right?

SELECT * FROM CIM_DataFile WHERE path='\\program files (x86)\microsoft office\office16\\' AND FileName='outlook' AND Extension='exe'

Finally, the only property I wish to get is the version. I simple need to SELECT the version property instead of the * wildcard.

SELECT Version FROM CIM_DataFile WHERE path='\\program files (x86)\microsoft office\office16\\' AND FileName='outlook' AND Extension='exe'

It was at this point I used PDQ Inventory to query all the workstations with Office 2016. If you don’t have access to a product that can do some ofthe heavy lifting for you, an alternative is PowerShell.

Here I have typed up a WMI query in PowerShell. First I created a variable to store the query (Creating a variable isn’t necessary, but makes things a bit cleaner).

$Query = "SELECT * FROM CIM_DataFile WHERE path='\\program files (x86)\microsoft office\office16\\' AND FileName='outlook' AND Extension='exe'"
Get-WmiObject -Query $Query

There is one issue, PowerShell is returning a bunch of data we don’t want. To resolve this, we simply need to pipe the Get-WmiObject to a ForEach-Object and specify theVersion variable.

$Query = "SELECT * FROM CIM_DataFile WHERE path='\\program files (x86)\microsoft office\office16\\' AND FileName='outlook' AND Extension='exe'"
Get-WmiObject -Query $Query | ForEach-Object {$_.Version}

This returns only the version property. From there you can use your PowerShell wizardry to query remote machines. Microsoft has great documentation on this process.