[download id=”56″]
I am preparing new runbook for System Center Orchestrator.
In this runbook I am going to try to help out on some of the challenges found in Software Updates.
In this case I needed to create maintenance windows from Opalis/Orchestrator. It is not supported by default, therefore I had to make or find a PowerShell script.
I discovered that no scripts was available, so I created below script. This is the first version, don’t hesitate to bring comments about it and about improvements.
but this can be used for the basic need.
I used the SDK example as inspiration
# //*************************************************************************** # // ***** Script Header ***** # // # // Solution: Config Mgr 2007 # // File: Crate-Maintanance-Window.ps1 # // Author: Jakob Gottlieb Svendsen, Coretech A/S. https://blog.ctglobalservices.com # // Purpose: # // # // # // Usage: .ps1 # // # // # // CORETECH A/S History: # // 1.0.0 JGS 26/09/2011 Created initial version. # // # // Customer History: # // # // ***** End Header ***** # //*************************************************************************** # //---------------------------------------------------------------------------- #// #// Global constant and variable declarations #/ #//---------------------------------------------------------------------------- cls #Create maintanance Window $SCCM_SERVER = "CTSCCM01" $SCCM_SITECODE = "DK1" $COLLECTION_ID = "DK1000D1" #maintanance window info #read more about the values here # http://msdn.microsoft.com/en-us/library/cc143300.aspx $serviceWindowName = "Scorch software update window" $serviceWindowDescription = "Temporary window for software compliance runbook" $serviceWindowServiceWindowSchedules = "001A9A7BB8100008" # 00:00:00 - 23:59:00 - Every day $serviceWindowIsEnabled = $true $serviceWindowServiceWindowType = 1 #//---------------------------------------------------------------------------- #// Main routines #//---------------------------------------------------------------------------- #create splatting package with wmi info. $SccmWmiInfo = @{ Namespace = "root\SMS\site_$SCCM_SITECODE" ComputerName = $SCCM_SERVER } $collsettings = Get-WmiObject @SccmWmiInfo -Query "Select * From SMS_CollectionSettings Where CollectionID = '$COLLECTION_ID'" if (!$collsettings) { $collsettings = ([WMIClass] "\\$SCCM_SERVER\root\SMS\site_$($SCCM_SITECODE):SMS_CollectionSettings").CreateInstance() $collsettings.CollectionID = $COLLECTION_ID $collsettings.Put() } #Get lazy properties $collsettings.Get(); #new service window $serviceWindow = ([WMIClass] "\\$SCCM_SERVER\root\SMS\site_$($SCCM_SITECODE):SMS_ServiceWindow").CreateInstance() $serviceWindow.Name = $serviceWindowName $serviceWindow.Description = $serviceWindowDescription $serviceWindow.ServiceWindowSchedules = $serviceWindowServiceWindowSchedules $serviceWindow.IsEnabled = $serviceWindowIsEnabled $serviceWindow.ServiceWindowType = $serviceWindowServiceWindowType $collsettings.ServiceWindows += $serviceWindow.psobject.baseobject $collsettings.Put() #//---------------------------------------------------------------------------- #// End Script #//----------------------------------------------------------------------------
I am trying to achieve the same thing and stumbled accross your script when searching for solutions. The problem I having is that when running both the MSDN sample code or your script above I get a WMI Generic Failure. You got any idea what this might be related to?
Hello Lararus.
On which line do you get the generic error?
it bet it mostly because of one of the values being invalid.
On the $collsettings.Put() line
Sorted it, you were right! The code i was using to create my schedule string was incorrect and so I was passing an invalid schedule…thanks for the help (and the powershell script!)
Hi,
I am trying to set RecurrentType of Service window as 1 ( which equals none) but could not see effect on the Schedule and still it shows as Daily. Can you help me
Do you set the service window schedules to “” ?
otherwise try that. Unfortunately i dont have a SCCM2007 env available anymore.