Thursday, April 30, 2015

SCCM 2012 : Powershell: Change collection refresh interval to 4 hours

How to change all collection refresh interval to 4 hours from one day.

Few weeks ago we had a requirement to change all our collections to refresh every 4 hours, which were set for one day. I found some information on the web and compiled it to following script which enabled us to change the refresh interval of collection.


Below scripts gets the collections which have the refresh interval of 1 day.

This script is provided as is and with no warranties, it's the sole responsibility of the user to ensure it is tested prior to running on prod environment. 
---------------------------------------------------------
#set your CAS server name

$casservername="the-cas-server-name"


#new refresh interval which we want to set

$Schedule = New-CMSchedule -RecurInterval Hours -RecurCount 4


#Get all collections which have the refresh interval matching one day, you can include a -name  *match-text* to get only a certain collections which have certain text in their name.

#ex: Get-CMDeviceCollection -name *visio* -> all collections containing visio in their name


$collections=Get-CMDeviceCollection  | select Name,RefreshSchedule,CollectionID  -ExpandProperty RefreshSchedule | ? {$_.DaySpan -eq 1}


foreach($collection in $collections)

{

$ThisCollectionID=$collection.CollectionID

write-host "Working on " $collection.Name

$collection.RefreshSchedule | %{write-host "Dayspan and hourspan "  $_.DaySpan $_.HourSpan}

#replace CAS with your CAS site ID.


$a = [wmi] "\\${casservername}\root\sms\site_CAS:SMS_Collection.CollectionID='$ThisCollectionID'"

$a.RefreshSchedule=$Schedule.psbase.ManagedObject

$a.put()

}




















No comments:

Post a Comment