Get Mailbox Size for All Users using PowerShell

We can find the total used space of mailbox of all users by using the exchange powershell cmdlet Get-MailboxStatistics. The Get-MailboxStatistics cmdlet is used to obtain information about a mailbox, such as the total size of the mailbox, the number of messages it contains, and the mailbox logon activity.

Summary:

Get Mailbox Size for Single User

Get-MailboxStatistics -Identity 'Kevin' | Select DisplayName,ItemCount,TotalItemSize

Note: If you are working with normal PowerShell console instead of Exchange Management Shell, you need to run the following command to import exchange management powershell cmdlets.

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Get Mailbox Size for All Users

To get malibox size of all the users, you need to give exchange server name as input paramater instead of user identity .Use the below powershell script to get mailbox size of all the users.

Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | 
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression= {$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime

Get a list of Mailboxes sorted by size:

The following powershell script get a list of mailboxes with sizes and sorted by size in Descending order, so that you
can easily find the users who are using high storage space in their mailbox.

Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | 
Sort-Object TotalItemSize -Descending |
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression={$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, 
LastLogonTime

Export Mailbox Size Report to CSV

We can export powershell output into CSV file using Export-CSV cmdlet. The following powershell script export all the user’s mailbox size, total messages and lastLogon time values into CSV file.

Get-MailboxStatistics -Server 'ExchSVR1' | Where {$_.ObjectClass -eq “Mailbox”} | 
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression={$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime | 
Export-CSV "C:\MailBoxSize-Report.csv" -NoTypeInformation -Encoding UTF8

CSV output of mailbox size report:

Exchange Powershell - Get Mailbox Size for All Users

Get Mailbox Size of specific set of users

You can use the exchange management powershell cmdlet Get-Mailbox to get specific set of mailbox enabled Active Directory users and pass user details to Get-MailboxStatistics cmdlet. You can apply filters in Get-Mailbox cmdlet to select users.

Get-Mailbox | Where {$_.DistinguishedName -like "*OU=TestOU,DC=TestDomain,DC=local*"} |
Get-MailboxStatistics | Where {$_.ObjectClass -eq “Mailbox”} | 
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Messages”;expression={$_.ItemCount}},
@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}, LastLogonTime

Advertisement

3 thoughts on “Get Mailbox Size for All Users using PowerShell”

  1. Good way of telling, and pleasant piece of writing to get information concerning my presentation subject
    matter, which i am going to convey in institution of higher education.

    Reply
    • The retention policy field comes with Get-Mailbox command. Can you try the below commands.

      $Result=@()
      $mailboxes = Get-Mailbox -ResultSize Unlimited
      $totalmbx = $mailboxes.Count
      $i = 1
      $mailboxes | ForEach-Object {
      $i++
      $mbx = $_
      $mbs = Get-MailboxStatistics $mbx.UserPrincipalName

      Write-Progress -activity “Processing $mbx” -status “$i out of $totalmbx completed”

      if ($mbs.TotalItemSize -ne $null){
      $size = [math]::Round(($mbs.TotalItemSize.ToString().Split(‘(‘)[1].Split(‘ ‘)[0].Replace(‘,’,”)/1MB),2)
      }else{
      $size = 0 }

      $Result += New-Object PSObject -property @{
      Name = $mbx.DisplayName
      UserPrincipalName = $mbx.UserPrincipalName
      TotalSizeInMB = $size
      SizeWarningQuota=$mbx.IssueWarningQuota
      StorageSizeLimit = $mbx.ProhibitSendQuota
      StorageLimitStatus = $mbs.ProhibitSendQuota
      RetentionPolicy = $mbx.RetentionPolicy
      }
      }
      $Result | Export-CSV “C:\MailboxSizeReport.csv” -NoTypeInformation -Encoding UTF8

      The above commands available in the below post without RetentionPolicy field : https://morgantechspace.com/2016/10/check-mailbox-size-and-usage-report-powershell.html

      Reply

Leave a Comment