SCOM PS Grid Widget – adding fake health state columns

The question of the day arrived from Jose (b|t):

Hey Oleg, wondering if you’d know whether it is possible to create a column using the createinstance method, whose type is a healthstate icon, the same way you have when you createfromobject? I’ve been trying to do that in many different ways, with no luck.

Do I know? Heck, I don’t! Actually, I had absolutely no time to get my hands dirty with SCOM visualization magic during last year. Fortunately, I had a chance to work with several SCOM presentation gurus from VIAcode team, so I learned some tricks. High time for the bloody reverse engineering exercise.

Quick search (just 2 hours of fun :)) takes me to Microsoft.SystemCenter.Visualization.Component.Library.DataProviders assembly, ScriptContext class. CreateWellKnownType public method looks very promissing. Some tests… reading code back and forth… trying to get a working sample… And here it goes – there are two ways to get a health state icon in the SCOM PS Grid widget:

Option 1: Based on enum values (0 – Uninitialized, 1 – Success, 2 – Warning, 3 – Error), maintenance mode will not be considered in this case.

$dataObjectA = $ScriptContext.CreateInstance("xsd://olegkapustin.com/MySchema");
$dataObjectA["Id"]="A"; 
$dataObjectA["Fake State"]=$ScriptContext.CreateWellKnownType("xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.OperationalDataTypes/MonitoringObjectHealthStateType",0)
$dataObjectA["Fake State Name"]="0 - Uninitialized";
$dataObjectA["Text 1"]="Hello";
$dataObjectA["Text 2"]="World";
$ScriptContext.ReturnCollection.Add($dataObjectA);  

$dataObjectB = $ScriptContext.CreateInstance("xsd://olegkapustin.com/MySchema");
$dataObjectB["Id"]="B";
$dataObjectB["Fake State"]=$ScriptContext.CreateWellKnownType("xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.OperationalDataTypes/MonitoringObjectHealthStateType",1)
$dataObjectB["Fake State Name"]="1 - Success";
$dataObjectB["Text 1"]="Stay with us,";
$dataObjectB["Text 2"]="World!";
$ScriptContext.ReturnCollection.Add($dataObjectB);

$dataObjectC = $ScriptContext.CreateInstance("xsd://olegkapustin.com/MySchema");
$dataObjectC["Id"]="C";
$dataObjectC["Fake State"]=$ScriptContext.CreateWellKnownType("xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.OperationalDataTypes/MonitoringObjectHealthStateType",2)
$dataObjectC["Fake State Name"]="2 - Warning";
$dataObjectC["Text 1"]="Goodbye";
$dataObjectC["Text 2"]="World";
$ScriptContext.ReturnCollection.Add($dataObjectC);

$dataObjectD = $ScriptContext.CreateInstance("xsd://olegkapustin.com/MySchema");
$dataObjectD["Id"]="D";
$dataObjectD["Fake State"]=$ScriptContext.CreateWellKnownType("xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.OperationalDataTypes/MonitoringObjectHealthStateType",3)
$dataObjectD["Fake State Name"]="3 - Error";
$dataObjectD["Text 1"]="Two hours of";
$dataObjectD["Text 2"]="research...";
$ScriptContext.ReturnCollection.Add($dataObjectD);

Outcome:
SCOM PS Grid Widget with icon

Option 2. Based on monitoring object’s state, maintenance mode is considered.

Get-SCOMClass -Name "Microsoft.Windows.Computer" | Get-SCOMMonitoringObject | %{
    $dataObject = $ScriptContext.CreateInstance("xsd://olegkapustin.com/MySchema");
    $dataObject["Id"]=$_.Id.ToString();
    $dataObject["Name"]=$_.DisplayName;
    $dataObject["HS"]=$ScriptContext.CreateWellKnownType("xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.OperationalDataTypes/MonitoringObjectHealthStateType",$_)
	$ScriptContext.ReturnCollection.Add($dataObject)
}

Outcome:

SCOM PS Grid Widget with icon from object

That’s it, Jose! Hope it helps.

Leave a Comment