Quantcast
Channel: Microsoft – JeffOps
Viewing all articles
Browse latest Browse all 120

PowerShell function to find groups with no users as members

$
0
0

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
        }
    }
}

Viewing all articles
Browse latest Browse all 120

Trending Articles