Scripts for Finding Empty SCOM Groups

OdgeUK 41 Reputation points
2021-04-20T15:54:06.73+00:00

Hi All

I'm preparing for a migration of SCOM from 1807 to 2019. It's going to be a Side-By-Side migration with no in-place upgrade. All new infrastructure.

One of the things I want to do is identify all custom groups that are now redundant, in the existing platform, by getting a report on all empty groups. Empty groups likely used to contain Windows Servers that have all now been decommissioned. As Groups in sealed MPs can't be as easily removed as Rules and Monitors, I'd like to ensure that I am removing any redundant groups from our Custom Discovery MPs, before they go into the new SCOM platform.

Can anyone point me any scripts that might read all SCOM Groups and spit out a count for each? We don't have any nesting, so recursive scanning of groups isn't required.

Operations Manager
Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,417 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Crystal-MSFT 43,381 Reputation points Microsoft Vendor
    2021-04-21T02:12:30.787+00:00

    @OdgeUK , I have tried to write a script which will query out all the group in unsealed MP without any member. Here is the script for the reference:

    Import-Module OperationsManager  
      
    $MPs = Get-SCOMManagementPack | ?{!$_.Sealed}  
    $MPGroupClasses = @()  
    foreach ($MP in $MPs) {  
        $MPClasses = $MP.GetClasses()  
        If ($MPClasses.count -gt 0) {  
            foreach ($Class in $MPClasses) {  
                If (($Class.Name -ne "System.Entity") -and (($Class.GetBaseTypes()).Name.Contains("System.Group"))) {  
                    $MPGroupClasses += $Class  
                }  
            }  
        }  
    }  
    $GroupsByMP = Get-SCOMGroup -Id $MPGroupClasses.Id  
      
    foreach ($Group in $GroupsByMP) {  
    $Members = $Group.GetRelatedMonitoringObjects()  
    If ($Members.count -eq 0){  
    $group}  
    }  
    

    89714-image.png
    Hope it can help.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. OdgeUK 41 Reputation points
    2021-04-21T12:42:02.637+00:00

    Thanks for this. Actually all our custom groups are in Sealed MPs, so that we can target Custom Rules and Monitors / Overrides to them. I'll have a look through your script though to see if I can modify it. Appreciate that.