26 November 2016 blogs Klaas Hulder 5 min read
Why would we want to create Live Maps Services using PowerShell?
Live Maps comes with an Authoring Console that makes creating Service very easy. But in some scenarios, you don’t want a human to create services. One of those scenarios could be that there is a System Center Orchestrator run book that creates Live Maps Services based on the Service Catalog in Service Manager, ServiceNow, or another BSM solution. Another scenario would be that you need to create a lot of Live Maps Services at once.
How does it work?
I really like PowerShell it is powerful in helping you automate simple and complex tasks and they made it easy to execute methods from .NET assemblies.
The Live Maps Authoring Console is written in .NET code and it only uses the SCOM SDK to make changes in SCOM. On the machine that the Live Maps Authoring Console is installed, you can open PowerShell and start doing the same as what’s possible using the Authoring Console UI.
I must say that you have to be careful calling .NET code in PowerShell. First, you need very detailed knowledge about how the classes and methods in the .NET assembly’s work and you have to keep in mind that the methods you call are not part of a SDK. This means the interface and behaviour of the .NET code can be changed after each release.
Explaining the PowerShell example script
At the bottom of this article, you can find a link to the example PowerShell script that can let you create services. The definition of those services are read from an xml file.
The script needs two parameters to operate: [line 1 – 4]
- An input folder containing one or more xml files.
- A name or IP address of a SCOM management server.
This script works with integrated security. If you want to use a user name and password login, you need to make a few changes.
After that, the script will check if the Live Maps Authoring Console is installed. [line 24 – 34]
This is required because it needs the .NET assemblies installed on the machine.
It than loads the SCOM SDK and Live Maps assemblies in memory. [line 36 – 42]
The following lines are for creating a connection to SCOM and initializing the Live Maps data access layer. [line 46 – 59]
To check if a service already exists, I load the service objects that are already in the database. [line 60]
A loop over all xml files in the input folder starts and the xml files get loaded one by one. [line 60 – 61]
For each xml file the service nodes are iterated over. [line 64]
The root folder is loaded from SCOM using the definition from the xml. [line 71] The ParentFolder format in the xml is management pack name and folder name separated by a ‘!’ char.
Now the check on if a service with the same name already exists is done. [line 81 – 82]
If the service does not already exist, a new service is created. [line 84]
A new management pack is created for this service. This newly created management pack will be used to set the membership rules of the service perspectives. [line 85 – 86] or [line 91]
Because I made it possible to support the full membership rule and xml format here, we also need to use the correct management pack references in the destination management pack. [line 94 – 107]
After that, the membership rules from the xml file, for the three service perspectives, are added to the correct Live Maps views. [line 110 – 178]
If there were membership rules defined in the xml, the changes are saved in SCOM. [line 182]
How do I define the Membership rules?
Management pack xml is not easy to read if you don’t have a deep knowledge of System Center. For this example, I did choose to use the format which is also used by SCOM itself.
With a few simple steps I will explain how you can do this without the indebt management pack xml knowledge.
- Create a new management pack using the SCOM Operations Console.
- In the Live Maps Authoring Console, create a new List view.
- Add the membership rules or explicit members you want and save the view.
- Then, export the management pack using the SCOM Operations Console.
- Open the management pack file in a text editor and lookup the <MembershipRules> tag.
- Copy <MembershipRules> begin and end tag and everything between it.
- Paste the xml to the servicedata.xml file between the <EndUserMembershipRules>, <ApplicationMembershipRules> or <InfrastructureMembershipRules> tags.
- After that, you can copy the management pack references to the servicedata.xml file.
The goal of this script was to show what is possible with PowerShell and the Live Maps Authoring Console. This is a good starting point in integrating Live Maps with other products.
If you are not using Live Maps yet or like to learn more, you can request a free trial key:
About: Klaas Hulder
Lead Developer- Savision
Klaas is Savision’s first employee. He has been working for Savision since it was founded by Dennis Rietvink and Douwe van de Voort in late 2006. At the moment he is leading the development team responsible for the development of Live Maps. He has over 17 years of software development experience working for banks, utility and telecom companies at EDS.
Klaas studied Information and Communication Technology in the Netherlands.