Share via


How can you document SCOM business services (distributed applications) and their related objects in the service tree?

I have needed to develop some powershell script to output SCOM business services (distributed applications) aka service trees and their related objects in the service tree.

Here is the powershell.

 $daClass=get-monitoringclass -name:System.Service 
 
 $da=get-monitoringobject -monitoringclass:$daClass 
 
 $objects=$da | foreach-object{$_.displayname} 
 
 $myxml = ""
 
 function bul($objectName) 
 { 
 $myxml = "<?xml version=""1.0""?>"
 $myxml = $myxml + "<service><servicename>" + $objectname + "</servicename><objects>"
 $results = ($da | ?{$_.displayname -eq $objectName} | %{$_.GetRelatedMonitoringObjects()}) | %{$_.GetRelatedMonitoringObjects()} | %{$_.displayname} 
 
 $i = 0
 foreach($result in $results) 
 { 
 $i = $i + 1
 $myxml = $myxml + "<object" + $i + ">" + $result + "</object" + $i + ">" 
 } 
 
 $myxml = $myxml + "</objects></service>"
 $myxml | Out-File "c:\temp\myservice.xml"
 } 
 
 if($args[0] -eq "list") 
 { 
 $myxml = "<?xml version=""1.0""?>"
 $myxml = $myxml + "<service>"
 
 foreach ($myobject in $da)
 {
 $myxml = $myxml + "<servicename>" + $myobject.displayname + "</servicename>"
 }
 $myxml = $myxml + "</service>"
 $myxml | Out-File "c:\temp\myslist.xml"
 } 
 else 
 { 
 bul($args[0]) 
 }
 

This powershell script can call with either list parameter to list all business services (distributed applications) or you can directly give any SCOM business service name as the first parameter to get its related objects defined in the service tree. Assume the name of script as "myscript.ps1". 

Open SCOM powershell and type:

 myscript.ps1 "list"

You will get c:\temp\myslist.xml file.

Open SCOM powershell and type:

 myscript.ps1 "mycustomservice"

You will get c:\temp\myservice.xml file.

 

Comments

  • Anonymous
    April 03, 2014
    Hi there,

    I'm really interested in this script (and the output), is there an version for SCOM 2012? Can you mail it to me (m dot steeg add g mail dot com)

    Thanks!

    regards,
    Marcel