This is probably because I work with multiple customer, with different environments, rather than just setting things up once within my own environment so this “Automate everything” approach will not apply to everyone. It’s about finding the value and ROI of spending the time designing/writing the automation versus the effort of manually doing the task.
That said, the latest one I went to tackle, was creating SLA working hours calendars within System Center 2012 R2 Service Manager (SCSM).
I had been on and off trying it for a while but picked it back up again the other week, but finally gave up banging my head on the desk (especially when I forgot to move my cup of coffee) and reached out for some help.
I sent a tearful email to my fellow SCSM Cookbook authors and Dieter Gasser, like the SCSM coding guru that he is, replied back in triple quick time with how to do this in PowerShell.
The basic outline principal for this is:
- Gather the classes for Calendar and Working Days
- Gather the Relationship between the two
- Gather the Enumerations for the Days
- Set an array for the Calendar and each Day with the Name, TimeZones, Start/End times and if they’re enabled or not
- Create new Objects for the Class based on those arrays
- Create the Relationships between the Days and the Calendar
- Commit them to the database
This was so easy in the end I (as usual) had been trying to boil the ocean with a bonfire instead of taking a cup full and using a kettle.
So thanks to Didi, I was able to take his simple code which went line by line setting each day and wrapped it into a script that queries an XML file allow modelling of multiple calendars and the streamlined creation of them.
I’ve uploaded the script and example XML file to the TechNet gallery as a zip file here:
The XML is fairly self-explanatory. For each calendar you would like to create, add a <SLACalendar> </SLACalendar> section and fill in the details for the days.
If you don’t want a day as a working day, just set it as Enabled=”False”
The only part I’ve not made easier yet is the TimeZone setting.
Currently you will need to find the string value used within SCSM and copy this to the XML.
This is fairly easy to find, just create a temporary calendar with the timezone you want and then run this PowerShell one-liner to display all the timezones in use:
(Get-SCSMObject -Class (Get-SCSMClass System.Calendar$)).TimeZone
Copy and paste the output to the XML.
Once you have the XML ready, create the calendars by running the script as so:
New-SCSMCalendar.ps1 –XMLFile <Path to XML>
e.g. New-SCSMCalendar.ps1 –XMLFile C:\Temp\Calendars.xml
Again, huge thanks to Didi with his help on this, be sure to check out his blog (http://blog.dietergasser.com/) or follow him on Twitter @DiGaBlog