This Module for SCCM 2007 (which does not come with a set of PowerShell Cmdlets) allows you to query Computers, Collections, Advertisements etc… (Check the Full list of Cmdlets)

However against big SCCM environment I notice some functions queries were very slow to report object.
After inspecting the code, I tweaked some parts of the code, especially on theGet-WmiObject queries.
Those modifications are now part of the module.

It took 42 seconds to finish this command, that’s pretty long…
Basically the command has to gather ALLLLLL the objects from the class SMS_R_Systemand then send it throught the pipe to Where-Object to filter on the ResourceID property.

WOW! This time Only 200 Milliseconds!! Pretty Awesome! Filtering is definitely the way to go! ;-)
All I did is really filtering on the ResourceID property with Get-WmiObject, I don’t need to retrieve all the data.

In Powershell you should Always Always Always ALWAYSStry to filter before sending the output to the pipeline, and this apply to all the Cmdlets…This was well resumed by the Scripting Guy, Ed Wilson [Top Ten PowerShell Best Practices]:

Filter on the left. It is more efficient to filter returning data as close to the source of data as possible. For example, you do not want to return the entire contents of the system event log across the network to your work station, and then filter events for a specific event ID. Instead, you want to filter the system event log on the server, and then return the data.