Command Shell Examples
Useful SQL Queries
Get-MonitoringClass - Jonathan Almquist on Operations Manager - Site Home - TechNet Blogs

Get-MonitoringClass

Get-MonitoringClass

  • Comments 2
  • Likes

This example demonstrates the Operations Manager Command Shell Get-MonitoringClass cmdlet, using the GetMonitoringProperties and FindHostClass methods.

While authoring a Management Pack, we need to know what MonitoringClass properties are available to us.  If you're like me, my curiosity always leads me looking into the various relationships between these classes and what properties I had available to me further up the path ($Target/Host/Property).  So, I decided to write a PowerShell script to help me in understanding these relationships and properties quickly.

What it does:

The output will display your target class properties, as well as the entire Base class path and its respective properties (if any).  It will then process the same for it's Host Class.  This will loop until the Hosting relationship has been exhausted, giving a view of the relationships and properties of your target class all the way up to System.Entity.

Usage:

.\getClassPath.ps1 <class_name>

Example of output:

image

#begin

##This script accepts a class name, and returns the entire
##Base class path. It also returns Host Class for each
##Base class returned. Essentially, you'll see the entire
##class path for the given class.
##Author: Jonathan Almquist
##Microsoft - Services - Premier Field Engineer
##version 1.0
##11-01-2008
##Usage = getClassPath.ps1 <class_name>
##Example = getClassPath.ps1 Microsoft.Windows.Computer

param($classname)
$ast = "-"
$class = get-monitoringclass | where {$_.name -eq $classname}
Write-Host ($ast * 50)
Write-Host "TARGET CLASS" $class
Write-Host ($ast * 50)`n
while ($class -ne "False")
    {
    $property = $class | foreach-object {$_.getMonitoringProperties()} | Select-Object name
    foreach ($value in $Property)
        {
        if ($value.name -ne $null)
            {
            write-host `t`t`t`t $value.name
            }
            else
            {
            Write-Host `t`t`t`t "No properties"
            }
        }
    write-host `n
    Write-Host ($ast * 50)
    Write-Host "BASE CLASS PATH for" $class
    Write-Host ($ast * 50)`n
    $baseclass = get-monitoringclass | where {$_.id -eq $class.base.id.tostring()}
    While ($baseclass.base.id -ne $NULL)
        {
        $baseclass.name
        $property = $baseclass | foreach-object {$_.getMonitoringProperties()} | Select-Object name
        foreach ($value in $Property)
            {
            write-host `t`t`t`t $value.name
            }
        $baseclass = get-monitoringclass | where {$_.id -eq $baseclass.base.id.tostring()}
        }
    if ($class.hosted -eq "True")
        {
        $hostclass = get-monitoringclass | where {$_.name -eq $Class.Name} | ForEach-Object {$_.findHostClass()}
        write-host `n
        Write-Host ($ast * 50)
        Write-Host "HOST CLASS for" $class
        Write-Host ($ast * 50)`n
        $class = get-monitoringclass | where {$_.name -eq $Class.Name} | ForEach-Object {$_.findHostClass()}
        Write-Host $class
        }
        else
        {
        write-host `t`t "*Not Hosted*" `n`n
        $class = "False"
        }
    }

#end

In case you've seen my previous version getClassChain, this is the same script.  I fixed an issue with the previous version, and renamed it.  Just thought this was a more fitting name...don't mean to confuse anyone ;)

Attachment: getClassPath.ps1

I do not moderate this blog anymore. If you have a question regarding this post, send me a message.

Comments