Categories

Common mistakes–filtering

Which of these should you use

Get-WmiObject -Class Win32_LogicalDisk | where DriveType -eq 3

or

Get-WmiObject -Class Win32_LogicalDisk -Filter {DriveType = 3}

They both give the same results after all.

Against a remote machine the first one took 640 milliseconds and the second took 245 milliseconds.

The reason for the difference is that the first command pulls back information on all logical disks – and then filters.  The second on pulls back information on drive type 3 (local hard disks)

The 395 milliseconds difference doesn’t sound much and against 1 machine is negligible.  No span that across hundreds or thousands of machines and you get a significant impact.

Always filter the data down as soon as you can – preferably at source.

Leave a Reply