The following script compares the members of two active directory groups

# Import the Active Directory module if it's not already loaded
if (-not (Get-Module -Name ActiveDirectory)) {
    Import-Module ActiveDirectory
}

# Specify the names of the two Active Directory groups
$groupName1 = "YourGroupName1"
$groupName2 = "YourGroupName2"

# Get the members of the two groups
$group1Members = Get-ADGroupMember -Identity $groupName1 -Recursive | Where-Object {$_.objectClass -eq "user"} | Select-Object -ExpandProperty SamAccountName
$group2Members = Get-ADGroupMember -Identity $groupName2 -Recursive | Where-Object {$_.objectClass -eq "user"} | Select-Object -ExpandProperty SamAccountName

# Get the unique users in the two groups
$allUsers = $group1Members + $group2Members | Sort-Object | Get-Unique

# Print out the results in a table format
$results = @()
foreach ($user in $allUsers) {
    $row = New-Object -Type PSObject
    $row | Add-Member -Type NoteProperty -Name "SamAccountName" -Value $user
    $row | Add-Member -Type NoteProperty -Name $groupName1 -Value $(if ($group1Members -contains $user) { "X" } else { "" })
    $row | Add-Member -Type NoteProperty -Name $groupName2 -Value $(if ($group2Members -contains $user) { "X" } else { "" })
    $results += $row
}

$results | Format-Table

By Rudy