Monday, January 13, 2014

PowerShell script to list SCCM 2012 collections that take long time to evaluate

Needed to list collections that were having evaluation delay issues. To do so, I put together a small script parsing Colleval log files & listing problematic collections. You might want to have a look at their queries & try to optimize them.
# created by Michael Sedenkov January 13, 2014
# Script listing SCCM 2012 Collections that are taking too long to be evaluated

$inputLogFiles = @("\\SCCM2012Server\logs$\colleval.lo_", "\\SCCM2012Server\logs$\colleval.log")
$evaluationTimeLimit = 60
$outputFile = "c:\temp\CollectionsRefreshDelay.csv"
$SCCMconnection = "\\SCCM2012Server\root\sms\site_SCCM2012Site"

write-Output "CollectionID;CollName;EvalDelaySeconds;Time" | Out-File $OutPutFile
write-host "CollectionID;CollName;EvalDelaySeconds;Time";
foreach ($file in $inputLogFiles) {
 cat $file |
  Select-String "PF: [Primary Evaluator] successfully evaluated collection" -SimpleMatch |
   select -expand line |
    foreach {
   #write-host $_
   $_ -match "PF: \[Primary Evaluator\] successfully evaluated collection \[(\w+)\] and used (\d+\.\d+) seconds  \$\$<(.{19})" | out-null
   if ([int]$matches[2] -ge $evaluationTimeLimit) {
    $ConnectionString = $SCCMconnection + ":SMS_Collection.CollectionID='" + $matches[1] +"'"
    $Coll = [wmi]$ConnectionString
    write-host $matches[1]"; " $Coll.Name"; " $matches[2]"; " $matches[3]
    write-Output "$($matches[1]);$($Coll.Name);$($matches[2]);$($matches[3])" | Out-File $OutPutFile -append
   }  
  }
 }

No comments:

Post a Comment