Script to list out Collection schedules of all collection in SCCM to a output file

Option Explicit

Dim objFSO : Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Dim objLogFile : Set objLogFile = objFSO.CreateTextFile(“Collections.log”)

Dim strSourceServer
strSourceServer = “XXX”
Dim strSourceSiteCode
strSourceSiteCode = “XXX”

Dim objSourceWMIService
Dim AllCollections
Dim objCollection
Dim strCollectionName
Dim strCollectionComment
Dim schedule
Dim schedtype
Dim bolScheduleAvailable
Dim strRecur
Dim strEvery

Set objSourceWMIService = GetObject(“winmgmts://” & strSourceServer & “\root\sms\site_” & strSourceSiteCode)

‘objLogFile.WriteLine Now & ” start ”

‘Loop trought all collections exsisting on the source server
Set AllCollections = objSourceWMIService.ExecQuery(“SELECT * FROM SMS_Collection WHERE NAME NOT LIKE ‘All%’ AND NAME NOT LIKE ‘Root%'”)

For Each objCollection In AllCollections
strCollectionName = objCollection.Name
strCollectionComment = objCollection.Comment

‘objLogFile.WriteLine Now & ” – Collection ” & objCollection.Name

Set objCollection = objSourceWMIService.Get(“SMS_Collection='” & objCollection.CollectionID & “‘” )

‘Get Collection schedule
On Error Resume Next
Set schedule = objCollection.RefreshSchedule(0)

On Error GoTo 0

If Err.Number = 424 Then
objLogFile.WriteLine “Collection has no Schedule ” & objCollection.Name
ElseIf Err.Number <> 0 Then
objLogFile.WriteLine “An Error (” & Err.Number & “) occured while getting the Update Schedule from ” & objCollection.Name
Else
‘On Error Resume Next
schedtype = Schedule.Path_.Class

Select Case (schedtype)
Case “SMS_ST_RecurInterval”
If schedule.MinuteSpan <> 0 Then strRecur = “Minute”
If schedule.HourSpan <> 0 Then strRecur = “Hour”
If schedule.DaySpan <> 0 Then strRecur = “Day”

If schedule.MinuteDuration <> 0 Then strEvery = schedule.MinuteDuration
If schedule.HourDuration <> 0 Then strEvery = schedule.HourDuration
If schedule.DayDuration <> 0 Then strEvery = schedule.DayDuration

bolScheduleAvailable = True
objLogFile.WriteLine objCollection.Name & “,Recurr every ” & strEvery & ” ” & strRecur & “,Starting ” & schedule.StartTime

Case “SMS_ST_RecurWeekly”

If schedule.ForNumberOfWeeks <> 0 Then strRecur = “Weekly”

bolScheduleAvailable = True
objLogFile.WriteLine objCollection.Name & “,Recurr every ” & strRecur & “,Starting ” & schedule.StartTime

Case “SMS_ST_RecurMonthlyByDate”

If schedule.ForNumberOfMonths <> 0 Then strRecur = “Monthly”
bolScheduleAvailable = True
objLogFile.WriteLine objCollection.Name & “,Recurr every ” & strRecur & “,Starting ” & schedule.StartTime
Case “SMS_ST_RecurMonthlyByWeekday”

Token.StartTime = schedule.StartTime
objLogFile.WriteLine Now & ” – SMS_ST_RecurMonthlyByWeekday Schedule available ” & objCollection.Name

bolScheduleAvailable = True

Case “SMS_ST_NonRecurring”

bolScheduleAvailable = True
objLogFile.WriteLine Now & ” – SMS_ST_NonRecurring Schedule available ” & objCollection.Name

Case Else
bolScheduleAvailable = False
objLogFile.WriteLine Now & ” – Unknown Schedule (skipping) ” & objCollection.Name
End Select

End If

Next

objLogFile.WriteLine Now & ” – Finish”
WScript.Echo “Done”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: