Hi,
I want to perform an SQL Query by Object class, that will show me the object name, its path, and its current state (same as discovered inventory on scom console).
Query that will return me same output as this powershell command:
Get-SCOMClass -Name "$classtype" | Get-SCOMClassInstance | Sort-Object HealthState,Path -Descending | select-object {$_.Path + " " + $_.displayname + "" + $_.HealthState + ""}
The thing is that powershell command takes 30 secs to run, thus I want to do it through SQL Query which is much faster.
I've wrote the query above:
SELECT distinct BME.BaseManagedEntityId, TBME.DisplayName AS Path, BME.DisplayName, TYPE.TypeName AS Class, CASE S.HealthState WHEN 3 THEN 'Critical' WHEN 2 THEN 'Warning' WHEN 1 THEN 'Success' WHEN 0 THEN 'Uninitialized' ELSE 'Unknown' END AS STATE, S.LastModified FROM BaseManagedEntity BME WITH(NOLOCK) INNER JOIN TypedManagedEntity TME WITH(NOLOCK) ON BME.BaseManagedEntityId = TME.BaseManagedEntityId AND BME.IsDeleted = 0 AND TME.IsDeleted = 0 INNER JOIN BaseManagedEntity TBME WITH(NOLOCK) ON BME.TopLevelHostEntityId = TBME.BaseManagedEntityId AND TBME.IsDeleted = 0 INNER JOIN ManagedType TYPE WITH(NOLOCK) ON TME.ManagedTypeID = TYPE.ManagedTypeID INNER JOIN State AS S ON S.LastModified = (select max(LastModified) from State where bme.basemanagedentityid=BaseManagedEntityId) where type.TypeName like 'Microsoft.Linux.Computer' order by STATEthe problem is that most of queried servers' state isshown as 'Uninitialized' while on scom console it is shown as helathy.
What am I doing wrong?