Friday, January 27, 2012

[SQL & SCOM] List SCOM groups for a list of servers

SELECT TargetMonitoringObjectDisplayName, SourceMonitoringObjectDisplayName AS 'Group'
FROM RelationshipGenericView
WHERE TargetMonitoringObjectDisplayName in ('MyServerFullName',
'MyServerFullName1')
AND (SourceMonitoringObjectDisplayName IN
(SELECT ManagedEntityGenericView.DisplayName
FROM ManagedEntityGenericView INNER JOIN
(SELECT BaseManagedEntityId
FROM BaseManagedEntity WITH (NOLOCK)
WHERE (BaseManagedEntityId = TopLevelHostEntityId) AND (BaseManagedEntityId NOT IN
(SELECT R.TargetEntityId
FROM Relationship AS R WITH (NOLOCK) INNER JOIN
dbo.fn_ContainmentRelationshipTypes() AS CRT ON R.RelationshipTypeId = CRT.RelationshipTypeId
WHERE (R.IsDeleted = 0)))) AS GetTopLevelEntities ON
GetTopLevelEntities.BaseManagedEntityId = ManagedEntityGenericView.Id INNER JOIN
(SELECT DISTINCT BaseManagedEntityId
FROM TypedManagedEntity WITH (NOLOCK)
WHERE (ManagedTypeId IN
(SELECT DerivedManagedTypeId
FROM dbo.fn_DerivedManagedTypes(dbo.fn_ManagedTypeId_Group()) AS fn_DerivedManagedTypes_1))) AS GetOnlyGroups ON
GetOnlyGroups.BaseManagedEntityId = ManagedEntityGenericView.Id))
ORDER BY 'Group'

Result will be like :


TargetMonitoringObjectDisplayNameGroup
MyServerFullName1agent group
MyServerFullNameagent group
MyServerFullName1Agent Managed Computer Group
MyServerFullNameAgent Managed Computer Group
MyServerFullName1All Windows Computers
MyServerFullNameAll Windows Computers
MyServerFullName1IIS 2003 Computer Group
MyServerFullNameIIS 2003 Computer Group
MyServerFullName1IIS Computer Group
MyServerFullNameIIS Computer Group
MyServerFullName1Windows Server 2003 Computer Group
MyServerFullNameWindows Server 2003 Computer Group
MyServerFullName1Windows Server Computer Group
MyServerFullNameWindows Server Computer Group
MyServerFullName1Windows Server Instances Group
MyServerFullNameWindows Server Instances Group

This posting is provided "AS IS" with no warranties.

No comments:

Post a Comment