Tags

, ,


Here we are going to see how to compare two Distribution Groups using Powershell. This will be most useful when you want to find the users those who are part of multiple groups. I have two groups are Sales-DL and Accounts-DL, let’s see how to compare both the groups. In this example I’m taking only few users where as in production it could be in hundreds.

Step 1: Storing Sales DL members into a Variable called $Sales

$Sales = Get-DistributionGroupMember –Identity “Sales-DL”

Step 2: Storing Accounts DL members into a Variable called $accounts

$Accounts = Get-DistributionGroupMember –Identity “Accounts-DL”

Step 3: Compare both the DL’s

Compare-Object –ReferenceObject $Sales –DifferenceObject $Accounts

You can see some Side Indicators from the output, they are:

“==” indicates that the object present in both the groups, here Kottees is part of both the DL’s

“=>” indicates that the object present only in the second group, here Accounts DL

“<=” indicates that the object present only in the first group, here Sales DL

Use below command to list the users only those who are part of both the Distribution Groups:

Compare-Object -ReferenceObject $sales -DifferenceObject $accounts -IncludeEqual | Where {$_.sideindicator -eq “==”} | foreach {$_.inputobject}

Here only “Kottees” is part of both Sales and Accounts groups. That’s what we were looking for.

Thanks for reading, Cheers!!!

Advertisements