PowerShell for Windows Admins

Oct 5 2013   5:41AM GMT

Common mistakes–filtering

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Which of these should you use

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


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.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: