WMI Server Side Filtering

Whenever you use Get-WMIObject, be sure to minimize resources and maximize speed by using server-side filtering. The next line will use the slow client-side filtering with Where-Object:

Get-WMIObject Win32_Service |
? {$_.started -eq $false} |
? { $_.StartMode -eq 'Auto'} |
? { $_.ExitCode -ne 0} |
Select-Object Name, DisplayName, StartMode, ExitCode

A faster and better approach is to filter on the WMI end by using the query parameter:

Get-WMIObject -Query ('select Name, DisplayName, StartMode, ' +
'ExitCode from win32_Service where Started=false ' +
'and StartMode="Auto" and ExitCode<>0')

Twitter This Tip! ReTweet this Tip!


Posted Apr 15 2010, 08:00 AM by ps1

Comments

Twitter Trackbacks for WMI Server Side Filtering - Power Tips - PowerShell.com [powershell.com] on Topsy.com wrote Twitter Trackbacks for WMI Server Side Filtering - Power Tips - PowerShell.com [powershell.com] on Topsy.com
on 04-15-2010 10:43 AM

Pingback from  Twitter Trackbacks for                 WMI Server Side Filtering - Power Tips - PowerShell.com         [powershell.com]        on Topsy.com

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.