[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
#//----------------------------------------------------------------------------