Forum Discussion

null null's avatar
null null
Copper Contributor
Apr 12, 2017

Powershell to remove empty security groups

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.

Chris

  • Try something like this:

     

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

  • null null's avatar
    null null
    Copper Contributor
    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.

Resources