Powershell to remove empty security groups

New Contributor

Just getting into Azure and imported a bunch of empty Security Groups into Azure AD.  Trying to sort out a way to delete Groups if they have 0 members.  Anyone got a quick way to do that?


Thank you.


3 Replies

Try something like this:


Get-MsolGroup -GroupType Security | ? {(Get-MsolGroupMember -GroupObjectId $_.ObjectId).count -eq 0 }

Thank you, that does get me a list of empty groups, I can pipe that to a file and use that to remove them I think.
http://www.garethjones294.com/bulk-removing-azure-active-directory-users-and-groups-using-powershell... Used your suggestion with this blog post and found what I needed. Thank you again.