Every now and then I need to get or compare the version of a file. Although this is a rather basic task, you’ll need to know the exact location of the file.
If you have a standardized environment, this wouldn’t be much of a problem… the file is at the same location on each server, right? 😉
But what if you don’t have that luxury? What if you only know the drive where the file is located?
You can use a simple CIM/WMI class for this:
Get-CimInstance -Query "SELECT * FROM CIM_DataFile WHERE Drive='C:' AND FileName='winword' AND Extension='exe'"
And if you don’t know the drive, simply don’t filter on that and the command will search through the entire target… logically this will take a lot more time 😉
Get-CimInstance -Query "SELECT * FROM CIM_DataFile WHERE FileName='winword' AND Extension='exe'"