Jeff Wouters's Blog

PowerShell function to find groups with no users as members

by on Nov.11, 2013, under Active Directory, DuPSUG, Microsoft, PowerShell

Groups with no members in them are, in my opinion, a waste of a perfectly good object 😉
So here is a function to find groups that have no users and no groups as member…

function Get-EmptyGroups {
    $Groups = Get-ADGroup -Filter * -Properties members
    foreach ($Group in $Groups) {
        $GroupMembers = $Group | Select-Object -ExpandProperty members
        if ($groupmembers -eq $null) {
            $Group.Name
        }
    }
}

Leave a Reply