none
In which groups and subs is my server ?

    General discussion

  • Hi All, here is a bit of code I put together to identify the groups a server belongs to and the Subs those groups belong to.

    I do not have a blog so I though I'd share it here.

    Cheers

    param ($rootMS, $computerFQDN)

         add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin ;
         set-location "OperationsManagerMonitoring::" -ErrorVariable errSnapin ;
         new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin ;
         set-location $rootMS -ErrorVariable errSnapin ;

    $containmentRel = Get-RelationshipClass -name:’Microsoft.SystemCenter.InstanceGroupContainsEntities’
    $computerClass = Get-MonitoringClass -name:”Microsoft.Windows.Computer”
    $criteria = "PrincipalName='" + $computerFQDN + "'"

    $computer = Get-MonitoringObject -monitoringClass:$computerClass -criteria:$criteria
    $relatedObjects = $computer.GetMonitoringRelationshipObjectsWhereTarget($containmentRel,[Microsoft.EnterpriseManagement.Configuration.DerivedClassTraversalDepth]::Recursive,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive)

    foreach($group in $relatedObjects)
     {
    #$group.SourceMonitoringObject.DisplayName
    Write-Host "--------------------"
    Write-Host "Group:" $group.SourceMonitoringObject.DisplayName
    Write-Host "Subs:"
    Get-NotificationSubscription | Where-Object {$_.Configuration.MonitoringObjectGroupIds -Like $group.SourceMonitoringObject.Id} | Select DisplayName
     [Array]$Groups = $groups + $group
     }

    Friday, November 08, 2013 5:06 PM

All replies