Use this PowerShell script to add a maintenance window to a collection going from 9pm to 5am
#Set Names
$CollectionName = “Collection Name”
$WindowName = “Daily 9pm to 5am”
#Occurs Every day at 11pm to 5am
$Schedule = New-CMSchedule -Start "01/01/2016 8:55 PM" -DurationCount 8 -DurationInterval Hours -RecurInterval Days -RecurCount 1
$Collection = Get-CMDeviceCollection -Name $CollectionName
New-CMMaintenanceWindow -CollectionID $Collection.CollectionID -Schedule $Schedule -Name $WindowName
Another window that you might want to set is to occur after hours and during the weekend. Here is a script to set that
#Set Names
$CollectionName = "Collection Name"
#Occurs Every day at 5pm to 5am
$WindowName = "Daily 5pm to 5am"
$Schedule = New-CMSchedule -Start "01/01/2016 5:00 PM" -DurationCount 12 -DurationInterval Hours -RecurInterval Days -RecurCount 1
$Collection = Get-CMDeviceCollection -Name $CollectionName
New-CMMaintenanceWindow -CollectionID $Collection.CollectionID -Schedule $Schedule -Name $WindowName
#Occurs Saturday at 4am to 6pm
$WindowName = "Saturday"
$Schedule = New-CMSchedule -Start "01/01/2016 4:00 AM" -DurationCount 14 -DayOfWeek Saturday -DurationInterval Hours -RecurCount 1
$Collection = Get-CMDeviceCollection -Name $CollectionName
New-CMMaintenanceWindow -CollectionID $Collection.CollectionID -Schedule $Schedule -Name $WindowName
#Occurs Saturday at 4am to 6pm
$WindowName = "Sunday"
$Schedule = New-CMSchedule -Start "01/01/2016 4:00 AM" -DurationCount 14 -DayOfWeek Sunday -DurationInterval Hours -RecurCount 1
$Collection = Get-CMDeviceCollection -Name $CollectionName
New-CMMaintenanceWindow -CollectionID $Collection.CollectionID -Schedule $Schedule -Name $WindowName
Sources:
- https://technet.microsoft.com/library/dn472934(v=sc.20).aspx
- https://www.systemcenterdudes.com/manage-sccm-maintenance-windows-with-powershell/
- https://docs.microsoft.com/en-us/powershell/module/configurationmanager/new-cmschedule?view=sccm-ps
- https://miketerrill.net/2013/10/15/creating-schedules-with-new-cmschedule/
- https://technet.microsoft.com/en-us/library/jj850116(v=sc.20).aspx
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-5.1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.