Search code examples
powershellwhere-clausewmic

Powershell WMIC Datafile Invalid Query?


I have searched and searched, but cannot figure out why this is returning an Invalid query error:

wmic datafile where name='c:\\program files (x86)\\Mozilla Firefox\\Firefox.exe' get version

I've tried it with an elevated PS as well, thinking that perhaps it was due to the permissions on the program files folders. I also tried it with case-sensitive path/filename. I've tried double quotes as well as single quotes, as well as no quotes. I've also tried replacing the double \'s with singles. I've even tried different files in different folder locations (like c:\temp); it seems that every time I use datafile where name, I get an invalid query, even if I leave off get version...

What in the world is going on?


Solution

  • Use PowerShell's Get-WmiObject (alias gwmi) native approach:

    $f = gwmi cim_datafile -Filter {Name='c:\\program files (x86)\\Mozilla firefox\\firefox.exe'}
    $f.Version