question

OdgeUK-1905 avatar image
0 Votes"
OdgeUK-1905 asked OdgeUK-1905 action

Scripts for Finding Empty SCOM Groups

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.

msc-operations-manager
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Crystal-MSFT avatar image
0 Votes"
Crystal-MSFT answered

@OdgeUK-1905, 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.



image.png (170.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OdgeUK-1905 avatar image
0 Votes"
OdgeUK-1905 answered OllieWoodall-8422 commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@OdgeUK-1905, Thanks for the reply. I notice our MPs are all sealed. We can change the following command to include all the MPs we created to accomplish we want. For example, if the name has some reference, we can query them via name or other attributes:
$MPs = Get-SCOMManagementPack | ?{!$_.Sealed}

I know you will look through it rand modify it. If there's any update, feel free to let us know.

0 Votes 0 ·

@OdgeUK-1905, How's everything going? I am writing to see if we have the right script. If there's anything else we can help. feel free to let us know.

Thanks and have a nice day!

0 Votes 0 ·