Exchange Management Shell – Distribution Group

Here, you can find some commands for the Exchange Management Shell, in order to monitor your distribution lists.

Exchange Management Shell

Retrieve all the members of a specific Distribution List

For retrieving all the members of a specific Distribution list, we execute the following comamnd:

Get-DistributionGroupMember -Identity "EnterDLNameHere" | Get-Mailbox | ft DisplayName,PrimarySMTPAddress

 

Result:

[PS] C:\>Get-DistributionGroupMember -Identity "#Dist_LIB_luxe" | Get-Mailbox |
ft DisplayName,PrimarySMTPAddress

DisplayName                             PrimarySmtpAddress
-----------                             ------------------
Phillip Adams                           phillip.adams@openlog.it
Wang Dan                                wang.dan@openlog.it
Ben Laurie                              ben.laurie@openlog.it
Xiao Qiang                              xiao.qiang@openlog.it
Chico Whitaker                          chico.whitaker @openlog.it

 

Export a result to a file

If you want to export the result of a command, you must add at the end of your command:

| Export-CSV C:\data.csv

 

Retrieve all the Distribution Groups where a specific email is associated to

We execute the following command:

Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "user@domain.com" }

Result:

[PS] C:\exchange>Get-DistributionGroup | where { (Get-DistributionGroupMember $_
 | foreach {$_.PrimarySmtpAddress}) -contains "antoine.lcavelier@openlog.it" }

Name                DisplayName         GroupType           PrimarySmtpAddress
----                -----------         ---------           ------------------
!Dist_AFH_Paris_... AFH.Paris.Alerts    Universal           AFH.Paris.Alerts...
#Dist_LIB_Bureau... Bureau Paris        Universal, Secur... Bureau.Paris@ope...
!Dist_AFH_Paris     AFH.Paris           Universal           AFH.Paris@openlog.it
#Dist_LIB_openl...  LIB.Openlog Paris   Universal, Secur... lib.nurun-pari...
#Dist_LIB_noc       LIB.NOC             Universal, Secur... lib.noc@openlog.it
#Dist_LIB_Monito... LIB.Monitoring      Universal           LIB.Monitoring@o...
#Dist_LIB_Admin_... LIB.Admin Hudson    Universal           lib.admin-hudson...
!Dist_AFH_Paris_... AFH.Paris.Reports   Universal           AFH.Paris.Report...
AVERTISSEMENT : Par défaut, seuls les 1000 premiers éléments sont renvoyés.
Pour modifier le nombre d'éléments renvoyés, spécifiez le paramètre «
-ResultSize ». Pour renvoyer tous les éléments, spécifiez « -ResultSize
Unlimited » (Remarque : le renvoi de tous les éléments peut prendre beaucoup de
 temps et consommer une grande quantité de mémoire en fonction du nombre réel
d'éléments). Il est déconseillé de stocker les résultats dans une variable ; au
 lieu de cela, canalisez-les vers une autre tâche ou utilisez un script pour
opérer des modifications par lot.

 

Retrieve all members of all Districutions Groups

You must write a little script for that, replist.ps1, which export these data to a csv file:

$DGrps = Get-DistributionGroup -ResultSize Unlimited;
foreach($DGrp in $DGrps)
{
    $GrpMbrs = Get-DistributionGroupMember -id $DGrp -ResultSize Unlimited;
    foreach($GrpMbr in $GrpMbrs)
    {
        $DGrp.name+","+$DGrp.PrimarySmtpAddress+","+$GrpMbr.DisplayName |Out-file -Filepath c:\exchange\report7.csv -append; 
    }
}

 

Result of our csv file:

#Dist_LIB_account_manager lib.account-manager@openlog.it Phillip Adams
#Dist_LIB_account_manager lib.account-manager@openlog.it Wang Dan
#Dist_LIB_account_manager lib.account-manager@openlog.it C. J. Hinke
#Dist_LIB_account_manager lib.account-manager@openlog.it Ben Laurie
#Dist_LIB_accueil lib.accueil@openlog.it Tashi Kham
#Dist_LIB_accueil lib.accueil@openlog.it Xiao Qiang
#Dist_LIB_accueil lib.accueil@openlog.it Chico Whitaker
#Dist_LIB_achatsdroits lib.achatsdroits@openlog.it
#Dist_LIB_Admin_Hudson lib.admin-hudson@openlog.it Wang Youcai
#Dist_LIB_Admin_Hudson lib.admin-hudson@openlog.it Daniel Ellsberg
#Dist_LIB_Admin_Hudson lib.admin-hudson@openlog.it Coleen Rowley
#Dist_LIB_Admin_Hudson lib.admin-hudson@openlog.it Rop Gonggrijp

 

Resources

http://www.o365info.com/2012/08/exchange-online-display-and-export.html

http://www.o365info.com/2012/08/manage-distribution-groups-by-using.html

Leave a Reply

Your email address will not be published. Required fields are marked *