Waclaw Chrabaszcz
... there is no spoon ...

SCCM2012 R2 – How to schedule collection refresh interval using PowerShell

Monday, November 18, 2013 9:55 AM

There was an open subject after my first post about scripting ConfigMgr. In the meantime I've migrated from SCCM 2012 SP1 to R2, so I am really not sure whether this commandlet works for legacy versions. Here's the good example how to use schedule token while you are creating a device collection.

 

$schedule = New-CMSchedule –RecurInterval Days –RecurCount 1
New-CMDeviceCollection -Name testDevCol -LimitToCollectionName "All systems" –RefreshSchedule $Schedule
Add-CMDeviceCollectionQueryMembershipRule -CollectionName "testDevCol" -QueryExpression "select * from SMS_R_System inner join
SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Name
like ""WKS-_______""" -RuleName "testRule"

There are various ways how you can define your schedule, of course, based on your needs

SYNTAX

New-CMSchedule [-IsUtc] [-ScheduleString] [-Start <DateTime>] -Nonrecurring [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfMonth <Int32> -End <DateTime> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfMonth <Int32> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfMonth <Int32> -DurationCount <Int32> -DurationInterval <ScheduleInterval> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfWeek {Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday} [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfWeek {Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday} -DurationCount <Int32> -DurationInterval <ScheduleInterval>-WeekOrder <ScheduleWeekOrder> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfWeek {Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday} -DurationCount <Int32> -DurationInterval <ScheduleInterval> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfWeek {Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday} -WeekOrder <ScheduleWeekOrder> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfWeek {Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday} -End <DateTime> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DayOfWeek {Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday} -End <DateTime> -WeekOrder <ScheduleWeekOrder> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -DurationCount <Int32> -DurationInterval <ScheduleInterval> -LastDayOfMonth [<CommonParameters>]

New-CMSchedule [-IsUtc] [-ScheduleString] [-Start <DateTime>] -DurationCount <Int32> -DurationInterval <ScheduleInterval> -RecurCount <Int32> -RecurInterval <ScheduleInterval> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-ScheduleString] [-Start <DateTime>] -DurationCount <Int32> -DurationInterval <ScheduleInterval> -Nonrecurring [<CommonParameters>]

New-CMSchedule [-IsUtc] [-ScheduleString] [-Start <DateTime>] -End <DateTime> -Nonrecurring [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] -End <DateTime> -LastDayOfMonth [<CommonParameters>]

New-CMSchedule [-IsUtc] [-ScheduleString] [-Start <DateTime>] -End <DateTime> -RecurCount <Int32> -RecurInterval <ScheduleInterval> [<CommonParameters>]

New-CMSchedule [-IsUtc] [-RecurCount <Int32>] [-ScheduleString] [-Start <DateTime>] –LastDayOfMonth [<CommonParameters>]

New-CMSchedule [-IsUtc] [-ScheduleString] [-Start <DateTime>] -RecurCount <Int32> -RecurInterval <ScheduleInterval> [<CommonParameters>]




Feedback

# re: SCCM2012 R2 – How to schedule collection refresh interval using PowerShell

Schedules, especially those setting maintenance windows have always been tough for me to wrap my head around using the SDK. I'm sure glad MS finally got some built-in cmdlets for ConfigMgr 2012. I've got dozens of custom cmdlets that I had to hack together for the 2007 world.

- Adam
adamtheautomator.com 11/23/2013 11:23 PM | Adam Bertram

Post a comment