Hi!
Is there any way through Powershell to find empty SCOM groups easily? With empty i mean with literally zero group members.
Hi!
Is there any way through Powershell to find empty SCOM groups easily? With empty i mean with literally zero group members.
Hey,
I have put a quick script together, tested it and it will report all your empty groups in green. Please try it out:
$Groups = Get-SCOMGroup
foreach ($Group in $Groups) {
if (!($Group.GetRelatedMonitoringObjects())) {
Write-Host "The group $($Group.DisplayName) is empty" -ForegroundColor Green
} else {
Write-Host "The group $($Group.DisplayName)is NOT empty" -ForegroundColor Red
}
}
I will very much appreciate your feedback!
(If the reply was helpful please don't forget to upvote or accept as answer, thank you)
Regards,
Stoyan
Hi,
sure..The code below will loop over all groups, show you if the group is empty or not (Red or Green) while collecting the data and dump (output) in white only the empty groups at the end:
#Create an array to store the empty groups
$AllEmptyGroups = @()
#Get all SCOM groups
$Groups = Get-SCOMGroup
#Check if the group has members or not
foreach ($Group in $Groups) {
if (!($Group.GetRelatedMonitoringObjects())) {
#Group Display Name
$CurrentEmptyGroup = $Group.DisplayName
Write-Host "The group $($Group.DisplayName) is empty" -ForegroundColor Green
#Add the current empty group to the collection
$AllEmptyGroups += $CurrentEmptyGroup
} else {
Write-Host "The group $($Group.DisplayName)is NOT empty" -ForegroundColor Red
}
}
#Output all empty groups
$AllEmptyGroups
If you don't want to display green or red while collecting the list ($AllEmptyGroups) you can just comment out the "Write-Host" part.
What you can do also is generate a CSV file with those groups:
#Create an array to store the empty groups
$AllEmptyGroups = @()
#Get all SCOM groups
$Groups = Get-SCOMGroup
#Check if the group has members or not
foreach ($Group in $Groups) {
if (!($Group.GetRelatedMonitoringObjects())) {
#Group Display Name
$CurrentEmptyGroup = $Group.DisplayName
Write-Host "The group $($Group.DisplayName) is empty" -ForegroundColor Green
#Add the current empty group to the collection
$AllEmptyGroups += $CurrentEmptyGroup
} else {
Write-Host "The group $($Group.DisplayName)is NOT empty" -ForegroundColor Red
}
}
#Output all empty groups
$AllEmptyGroups | Export-Csv C:\Temp\EmptyGroups.csv -Delimiter ";" -NoTypeInformation -Encoding UTF8
Hope I could help.
(If the reply was helpful please don't forget to upvote or accept as answer, thank you)
Regards,
Stoyan
Thank you very much for your help and time Stoyan!
The first script is what we need right now so I'll use it for now. I also tried the second one but I only got a bunch of columns with numbers when i opened the csv?
Anyway, thank you for your help again.
Regards
Jakob
Hi Jakob,
glad to help you out. If you run the second script and generate a .csv file, please open it with excel and follow this (attention, it is not a Microsoft link):
How to open a CSV file in Excel?
https://www.copytrans.net/support/how-to-open-a-csv-file-in-excel/
and you will get a nice output :)
Hope I was able to help. Regards!
Stoyan
5 people are following this question.