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.


2 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.