Comparing AD groups' membership
Sometimes, you might find a need to compare membership of two security groups. This is generally required to find whether they are identical. This not only helps in getting rid of duplicate groups, but also in troubleshooting permission issues. The function discussed in the following code takes two group names as input and compares their members. The output contains a report that shows the number of objects that exist in both the groups, and the number of objects that are found in the first group but not the second and vice versa:
Function Compare-ADGroups { [CmdletBinding()] Param( [Parameter(Mandatory=$true, Position = 0)] [String]$Group1, [Parameter(Mandatory=$true, Position = 1)] [String]$Group2, [Parameter(Position = 2)] [switch]$Nested ) try { $Group1Obj = @(Get-ADGroupMember -Identity $Group1 - Recursive:$Nested -EA Stop) $Group2Obj = @(Get-ADGroupMember -Identity $Group2 - Recursive:$Nested -EA Stop) } catch { Write-Warning "Failed...