I’ve tended to advocate using the –Filter parameter rather than the –Query parameter with the CIM (and WMI) cmdlets but a recent post on the Windows Management Infrastructure blog has me questioning that decision.
Using Measure-Command I tried various pairs of commands – such as:
Measure-Command {Get-CimInstance -ClassName Win32_Directory -Filter "Name = ‘C:\\Test2’"}
Measure-Command {Get-CimInstance -Query "SELECT * FROM Win32_Directory WHERE Name = ‘C:\\Test2’"}
The results weren’t conclusive but it seems that at worst there is no significant difference between the approaches and at best using a query is significantly faster.
At the moment my best advice would be use the –Filter parameter if you want to reduce typing but try –Query if speed becomes your main issue.