Blog
By Pete Zerger on 9/22/2009 8:19:36 PM • Rank (1601) • Views 1791
0

0

Here's a quick-and-dirty Powershell snippet for OpsMgr I was playing with you might find useful for exploring class lineage in OpsMgr. Given a target class, this bit of Powershell will present the classes based on that class you add to the $Class variable

For example, given System.Entity (the base class in OpsMgr):

  • Script will return child classes of System.Entity, which are System.PhysicalEntity, System.LogicalEntity and Microsoft.Unix.SupportedAgent (R2 with X-Plat only).
  • Then returns to the screen all classes using each of these as their base class. In other words, all classes derived from Physical and Logical Entity.

Nothing fancy, but does provide an easy way to enumerate classes without opening multiple MPs in the MP Viewer or Authoring console. A bit of playing and we could create a function to return all child classes and their children recursively…I will have to play around a bit longer for that when time allows.

 

Sample Script (save with .ps1 extension run from OpsMgr Command Shell prompt)

   1:  #Replace system.entity with the class of your choice
   2:  $Class = 'system.entity'
   3:   
   4:  foreach ($baseclass in $baseclasses) {
   5:   
   6:  $DerivedClasses = (get-monitoringclass | where {$_.Name -eq "$Class"}).GetDerivedMonitoringClasses()
   7:   
   8:  foreach ($DerivedClass in $DerivedClasses) {
   9:      Write-Host " "
  10:      Write-Host "Derived classes based on " $DerivedClass.DisplayName "(" $DerivedClass.Name ")"
  11:      Write-Host "The following classes are derived from " $DerivedClass.DisplayName ":"
  12:  (get-monitoringclass -Name $DerivedClass ).GetDerivedMonitoringClasses() | select DisplayName, Name 
  13:  }
  14:  }

 

Sample Output

image

Comments - Comment RSS


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/nxtbbl

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert