January 2015
Intermediate to advanced
230 pages
5h 4m
English
The PowerShell function discussed in this section helps you to find out the groups that have no members in them. This function has an optional switch parameter called -Nested, which indicates that a group has to be queried recursively for membership to determine whether it is empty or not. In some cases, a group can have another group in it, which might be empty as well. This switch will come in handy to find such cases:
Function Find-EmptyADGroups { [CmdletBinding()] Param( [switch]$Nested ) $Groups = Get-ADGroup -Filter * Write-Host "`nBelow is the list of empty groups in Active Directory`n`n" $Count = 0 foreach($Group in $Groups) { $Members = Get-ADGroupMember -Identity $Group -Recursive:$Nested if(!$Members) ...Read now
Unlock full access