best business builder

Exchange Powershell – Find Mailbox size of users in a Distribution List

Say that I have a Distribution List called “Finance Team“. At first I will have to find out the members of the Distribution List so then I can individually find their mailbox sizes.

$GroupName = Read-Host "Kindly provide the name of the Distribution Group"
Get-DistributionGroupMember $GroupName | Select Name | Export-Csv c:\Members.csv -NoTypeInformation

Let us see what did we do in the above two lines. At first once the script is made to run, it will prompt you for the name of the Distribution Group.

Once you provide the name, it will store it in a variable and then get the members of the group using Get-DistributionGroupMember.

We will select only the name and create a csv file called Members.csv.

$Members = Import-Csv C:\Members.csv
Foreach ($Member in $Members){
Get-MailboxStatistics $Member.Name | Select DisplayName, TotalItemSize
}

In the next step you will import the csv file that we just created into a variable called $Members.

Using Foreach loop, we will find the mailbox size of all the members of the group one by one.

Exchange Powershell - Find Mailbox size of users in a Distribution List

So the final script will look as below.

$GroupName = Read-Host "Kindly provide the name of the Distribution Group"
Get-DistributionGroupMember $GroupName | Select Name | Export-Csv c:\Members.csv -NoTypeInformation
$Members = Import-Csv C:\Members.csv
$Result = Foreach ($Member in $Members){
Get-MailboxStatistics $Member.Name | Select DisplayName, TotalItemSize
}
$Result | Export-Csv C:\Result.csv

Save this a .ps1 file and execute using Exchange Management Shell. I have added another line to export the final result as a csv file for easy maintenance.

customer relationships

Leave a Reply

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