Looking at WQL query vs a Get-WmiObject filter on the local machine we saw that they were practically the same. If we used a where-object to do the filtering it took nearly twice as long.
I wanted to repeat these runs against a remote machine. I use two Windows 2008 R2 servers for the test.
PS> 1..100 | foreach {Measure-Command -Expression {Get-WmiObject -Class Win32_Process -Filter "Name=’Notepad.exe’" -computername webr201}} |
Measure-Object -Property TotalMilliseconds -Average
Count : 100
Average : 29.678681
Sum :
Maximum :
Minimum :
Property : TotalMilliseconds
PS> 1..100 | foreach {Measure-Command -Expression {Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name=’Notepad.exe’" -computername webr201}} | Measure-Object -Property TotalMilliseconds -Average
Count : 100
Average : 30.669341
Sum :
Maximum :
Minimum :
Property : TotalMilliseconds
PS> 1..100 | foreach {Measure-Command -Expression {Get-WmiObject -Class Win32_Process -computername webr201 | Where {$_.Name -eq ‘Notepad.exe’} }} |
Measure-Object -Property TotalMilliseconds -Average
Count : 100
Average : 59.997321
Sum :
Maximum :
Minimum :
Property : TotalMilliseconds
Results Summary
Filter: 29.678681
Query: 30.669341
Where: 59.997321
Again the filter and the query are nearly the same. I millisecond difference in the average of 100 runs is not enough to worry about. Using where-object is again about twice the time.
The results this time are quicker than running on the local machine. This is because the server I used is more powerful than the laptop I used for the local test. The important thing is the relationships not the exact numbers. I ran the tests locally on the server and got similar pattern of results.
After all this I would say the running a full WQL query or using –Filter are about the same in speed. There may be a gain for the query if we selected properties as well but the extra typing and checking probably don’t justify the gain. Use a query or use a filter the results will be similar. I’ll stick with the filter because its less typing.