Monitoring Object Properties

There has been some question about how to get properties for monitoring objects with Command Shell.  I wanted to go into this in my MMS session last week, but I already ran out of time just trying to cram in all the topics I did cover.  Shouldn't be too tough to explain it here though.

If you use Get-MonitoringObject, you get a common set of properties for all objects.  Kind of like the following:

 PS Monitoring:\OpsMgr01
>$mc = get-monitoringClass -name Microsoft.Windows.Computer
>$mc | get-monitoringObject | where {$_.name -match 'web01'} 

Id               : 0844f543-762c-5800-794c-a72a1823ea96
PathName         : web01.greengargantua.com
DisplayName      : web01.greengargantua.com
ManagementMode   :
ManagementGroup  : gaira
HealthState      : Success
OperationalState : 

PS Monitoring:\OpsMgr01
>$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database 
>$mc | get-monitoringObject | where {$_.name -match 'blob'} 
 

Id               : dfd4fd2b-6c7f-6c9c-a1cd-4d074613e3fd
PathName         : opsmgr01.greengargantua.com%003bMSSQLSERVER%003ablob
DisplayName      : blob
ManagementMode   :
ManagementGroup  : gaira
HealthState      : Success
OperationalState : 

That example shows two objects that are completely different - a database and a computer - but we show an identical set of properties.  We know that there a bunch of properties unique to each of those classes, but where are they?

In order to display all properties for the object, you can use one of the Format CmdLets with * indicating you want all properties.  That results in the following: 

 PS Monitoring:\OpsMgr01
>$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database
>$mc | get-monitoringObject | where {$_.name -match 'blob'} | fl * 

PathName                                        : opsmgr01.bwren.com%003bMSSQLSERVER%003ablob
UniquePathName                                  : Microsoft.SQLServer.Database%003aopsmgr01.bwren.com%003bMSSQLSERVER%003bblob
[Microsoft.SQLServer.Database].DatabaseName     : blob
[Microsoft.SQLServer.Database].RecoveryModel    : FULL
[Microsoft.SQLServer.Database].DatabaseAutogrow : True
[Microsoft.SQLServer.Database].DatabaseSize     : 2
[Microsoft.SQLServer.Database].LogAutogrow      : True
[Microsoft.SQLServer.Database].Updateability    : READ_WRITE
[Microsoft.SQLServer.Database].UserAccess       : MULTI_USER
[Microsoft.SQLServer.Database].Collation        : SQL_Latin1_General_CP1_CI_AS
[Microsoft.SQLServer.Database].LogSize          : 1
[Microsoft.SQLServer.Database].Owner            : BWREN\Administrator
[System.Entity].DisplayName                     : blob
Name                                            : blob
Path                                            : opsmgr01.bwren.com;MSSQLSERVER
DisplayName                                     : blob
FullName                                        : Microsoft.SQLServer.Database:opsmgr01.bwren.com;MSSQLSERVER;blob
IsManaged                                       : True
LastModified                                    : 11/26/2007 7:07:20 AM
HealthState                                     : Success
StateLastModified                               : 5/1/2008 8:39:45 PM
IsAvailable                                     : True
AvailabilityLastModified                        : 5/3/2008 5:20:29 PM
InMaintenanceMode                               : False
MaintenanceModeLastModified                     : 5/1/2008 8:39:06 PM
MonitoringClassIds                              : {10c1c7f7-ba0f-5f9b-c74a-79a891170934, cae6be07-6483-361b-710f-c7612e29fa7b}
LeastDerivedNonAbstractMonitoringClassId        : 10c1c7f7-ba0f-5f9b-c74a-79a891170934
Id                                              : dfd4fd2b-6c7f-6c9c-a1cd-4d074613e3fd
ManagementGroup                                 : bwren
ManagementGroupId                               : 80342cfb-a3e1-aa59-7eac-cb5b5f167c38 

The properties specific to the individual class are preceded with the name of the class they came from surrounded by brackets.  I'll explain the details of that later.  For now, just know that you have to specify the entire thing to retrieve the property value.  Since PowerShell sees those brackets as special characters, you need to surround the entire property name with quotes. 

 >$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database
>$mo = $mc | get-monitoringObject | where {$_.name -match 'blob'}
>$mo."[Microsoft.SQLServer.Database].LogAutogrow"

That syntax can actually get tricky, and I'll be honest that I haven't figured out how to get it working in all cases.  The other approach you can use is the Get-MonitoringObjectProperty CmdLet.  The name property from that CmdLet will be the simple name of the property. 

 >$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database 
>$mo = $mc | get-monitoringObject | where {$_.name -match 'blob'} 
>$mo | get-monitoringObjectProperty | sort parentElement,name | ft parentElement,name,value 

ParentElement                         Name                      Value
-------------                         ----                      -----
Microsoft.SQLServer.Database          Collation                 SQL_Latin1_General_CP1_CI_AS
Microsoft.SQLServer.Database          DatabaseAutogrow          True
Microsoft.SQLServer.Database          DatabaseName              blob
Microsoft.SQLServer.Database          DatabaseSize              2
Microsoft.SQLServer.Database          LogAutogrow               True
Microsoft.SQLServer.Database          LogSize                   1
Microsoft.SQLServer.Database          Owner                     BWREN\Administrator
Microsoft.SQLServer.Database          RecoveryModel             FULL
Microsoft.SQLServer.Database          Updateability             READ_WRITE
Microsoft.SQLServer.Database          UserAccess                MULTI_USER
System.Entity                         DisplayName               blob

If you already know about the concept of base classes in OpsMgr, then you already know what that that ParentElement class is.  If not, let me provide a very brief description just so you at least have a little background information.If you want more details on this whole concept of class structures in OpsMgr, the Authoring Guide has complete documentation.

All classes in OpsMgr have a base class.  That base class may have a base class, and its base class may have a base class, etc.  All classes will eventually find their way up to System.Entity which is the only class with no base.  The object tree for the SQL 2005 Database class is shown below.

image

 

If a class has properties associated with it, then any classes that inherit from it (ie. they use that class as their base class) inherit its properties and any properties along the class tree.  There are no properties explicitly assigned to SQL 2005 Database.  Instead, those properties you see (Collation, DatabaseAutogroup, etc) are defined on the SQL Database class.  As you might imagine, SQL 2000 Database inherits from that same class so it inherits the same properties as SQL Database.