I recently needed to retrieve the object model from Operations Manager 2012. I needed this information so that I could pass the "target" collection back to the developers for proper targeting when creating new monitors. I wanted each developer to have a better understanding of the object model and how to target the correct class.
I wrote this PowerShell script in order to retrieve the OM and export it to an XML file for viewing.
function
GetDerivedClasses([object]$DerivedClass)
{
$DerivedClasses = @($DerivedClass; $DerivedClass.GetDerivedTypes())
$DName = $xml.CreateElement($DerivedClass.Name)
$CurrentNode.AppendChild($DName)
if ($DerivedClasses.Count -gt 1)
{
$CurrentNodeString = $CurrentNodeString + "/" + $CurrentNode.LastChild.ToString()
$CurrentNode = $xml.SelectSingleNode($CurrentNodeString)
foreach ($DClass in $DerivedClasses)
{
if($DerivedClass -ne $DClass)
{
$SCClass = Get-SCOMClass -Name $DClass.Name
GetDerivedClasses($SCClass)
}
}
}
}
New-SCManagementGroupConnection -ComputerName "SCOM2012"
$xml
= New-Object -typeName xml
$root
= $xml.CreateElement("SCOMClasses")
[
void]$xml.AppendChild($root)
$root.SetAttribute("xmlns", "http://schemas.datacontract.org/2004/07/SCOMClasses")
$OFile
= "C:\SCOMObjects.xml"
$CurrentNodeString
= $xml.SCOMClasses.ToString()
$CurrentNode
= $xml.SCOMClasses
$RootClass
= Get-SCClass -name "System.Entity"
GetDerivedClasses(
$RootClass)
$xml
.save($OFile)
Hope this helps.