SCCM: Determining collection refresh time using PowerShell

Monday, 21. June 2010

I recently had a need to examine the last refresh time of a large number of SCCM collections. We had a group of collections which are used to define maintenance windows for various servers, and we wanted to ensure that all these collections were updating regularly (and to fix the ones that weren’t).

Normally, I would take such a boring task and look for some way to automate it. I have a co-worker who evangelizes about the merits of PowerShell every chance he gets and we were able to put together a few lines to get the information I was looking for.

So obviously this requires that you have PowerShell installed, and it does require PowerShell v2. We used the SCCM PowerShell module located here, which appears to be the most “complete” unofficial PowerShell module I’ve found so far.

Once your PowerShell environment is configured, connecting to an SCCM server is as easy as:
$SCCMServer = Connect-SCCMServer servername

Next, you can do other things like:
# get all SCCM collections
$AllCollections = Get-SCCMCollection -SccmServer $SCCMServer

#show all not updated today
$a | where {$_.LastRefreshTime -notlike ‘20100621*’} | select Name

Instead of getting a list of all collections, you could target only certain ones:
$a = Get-SCCMCollection -sccmserver $sccm | where {$ -like 'Test*'} | Select name

The lines above were enough to save me tons of time I would otherwise spend manually verifying each collections properties. There are plenty of other opprotunities in this module including the ability to gather all sorts of information about advertisements, collections, sites, and packages, and I plan to continue to look for opprotunities where using these tools can allow me to work more efficiently.

Leave a Reply