skip to Main Content

Get mailbox size of all users in Exchange with PowerShell

We want to get the mailbox size of all users in Exchange with PowerShell. But why do we need to list the mailbox size for all users? For example, you want to migrate the users to a new Exchange Server/Exchange Online. Before doing that, find all the users’ mailbox sizes in Exchange Server/Exchange Online. The script that we will use in this article will gather 22 types of data per mailbox.

Information get mailbox size of all users PowerShell script

The MailboxSizeReport.ps1 PowerShell script works for:

  • Exchange on-premises
  • Exchange Online

You must connect with the proper tools before you run the script:

The MailboxSizeReport.ps1 PowerShell script got 7 options:

  1. Display in Exchange Management Shell
  2. Export to CSV File
  3. Export to CSV File (Specific to Database)
  4. Enter the Mailbox Name with Wild Card (Export)
  5. Enter the Mailbox Name with Wild Card (Display)
  6. Export to CSV File (OFFICE 365)
  7. Enter the Mailbox Name with Wild Card (Export) (OFFICE 365)

Note: Use options 1-5 for Exchange on-premises. Use options 6-7 for Office 365.

The script will run and find all users with a mailbox. It will gather the following information per mailbox in the CSV file:

  1. Display Name
  2. Alias
  3. SamAccountName
  4. RecipientType
  5. Recipient OU
  6. Primary SMTP address
  7. Email Addresses
  8. Database
  9. ServerName
  10. TotalItemSize
  11. ItemCount
  12. DeletedItemCount
  13. TotalDeletedItemSize
  14. ProhibitSendReceiveQuota-In-MB
  15. UseDatabaseQuotaDefaults
  16. LastLogonTime
  17. ArchiveName
  18. ArchiveStatus
  19. ArchiveState
  20. ArchiveQuota
  21. ArchiveTotalItemSize
  22. ArchiveTotalItemCount

Get mailbox size of all users with PowerShell script

Download and place MailboxSizeReport.ps1 PowerShell script in the C:\scripts folder. This script is made by Satheshwaran Manoharan. If you don’t have a scripts folder, create one. Make sure to check if the file is unblocked to prevent any errors when running the script.

Read more: Not digitally signed error when running PowerShell script »

Get mailbox size of all users in Exchange with PowerShell scripts folder

Run Exchange Management Shell or PowerShell as administrator. This depends on which option you like to choose in the script.

Run the following commands to change the directory path and start the script. It will display the Mailbox Size Report script.

[PS] C:\>cd c:\scripts

[PS] C:\scripts>.\MailboxSizeReport.ps1


Mailbox Size Report
----------------------------

1.Display in Exchange Management Shell

2.Export to CSV File

3.Export to CSV File (Specific to Database)

4.Enter the Mailbox Name with Wild Card (Export)

5.Enter the Mailbox Name with Wild Card (Display)

6.Export to CSV File (OFFICE 365)

7.Enter the Mailbox Name with Wild Card (Export) (OFFICE 365)

Choose The Task:

The script got 7 options. The one that we are looking for is option 2. Export to CSV File.

Insert 2 and press Enter.

[PS] C:\scripts>.\MailboxSizeReport.ps1


Mailbox Size Report
----------------------------

1.Display in Exchange Management Shell

2.Export to CSV File

3.Export to CSV File (Specific to Database)

4.Enter the Mailbox Name with Wild Card (Export)

5.Enter the Mailbox Name with Wild Card (Display)

6.Export to CSV File (OFFICE 365)

7.Enter the Mailbox Name with Wild Card (Export) (OFFICE 365)

Choose The Task: 2
Enter the Path of CSV file (Eg. C:\Report.csv):

The Mailbox Size Report PowerShell script will ask for a path. The export of the CSV file will get exported to that path.

Insert the following path: C:\scripts\report.csv and press Enter.

[PS] C:\scripts>.\MailboxSizeReport.ps1


Mailbox Size Report
----------------------------

1.Display in Exchange Management Shell

2.Export to CSV File

3.Export to CSV File (Specific to Database)

4.Enter the Mailbox Name with Wild Card (Export)

5.Enter the Mailbox Name with Wild Card (Display)

6.Export to CSV File (OFFICE 365)

7.Enter the Mailbox Name with Wild Card (Export) (OFFICE 365)

Choose The Task: 2
Enter the Path of CSV file (Eg. C:\Report.csv): C:\scripts\report.csv

The Mailbox Size Report PowerShell script starts scanning the mailboxes in the organization. This can take some time. When done, a list is created and exported in a CSV file. You can exit the script.

Result mailbox size report of all users in Exchange

Let’s see if the script made the export successful by going to the following path: C:\scripts\. You should see the report.csv file.

Get mailbox size of all users in Exchange with PowerShell exported CSV in folder

Open report.csv with your favorite application, for example with Microsoft Excel.

If you don’t need all the information, you can remove those columns. You can sort the file by Display Name, TotalItemSize, or by any other type. Tweak the information to your needs.

Get mailbox size of all users in Exchange with PowerShell csv report

Everything looks great!

Keep reading: Export Office 365 mailbox permissions to CSV »

Conclusion

You learned how to get the mailbox size of all users in Exchange/Exchange Online with PowerShell. Use the MailboxSizeReport PowerShell script to list the mailbox size for all users in the organization. It’s a great script, and you should use it more often to get the mailbox size and extra information.

Did you enjoy this article? You may also like Export AD users to CSV with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 19 Comments

  1. Hi Ali, Thank you for the script. it’s working fine.

    May I know the Total count is in what type? KB or GB?

    Assuming I have this results,

    240
    9731
    26117

    Thank You

    1. You did get these errors because the download didn’t save as it should. Please try again and ensure that you do save the PowerShell script correctly.

      A good way is to open the PowerShell script with PowerShell ISE or Notepad and verify it looks good.

  2. Hi Ali,

    When I run your script I was able to see just the archive mailboxes but not user’s regular mailboxes. Can you help me why I”m not getting it? TIA

    1. Hi Tommy,

      Export the mailboxes to CSV file and open the file with Notepad first. Then, confirm that you see the values.

      To import the CSV file in Microsoft Excel, follow these steps:

      1. Start Microsoft Excel
      2. Click in the tab on “Data”
      3. Click in the ribbon on “From Text/CSV”
      4. Select the CSV file

  3. When I run ps script:

    I don’t see tabs below:
    TotalItemSize
    ItemCount
    DeletedItemCount
    TotalDeletedItemSize

    So basically I don’t see user’s mailbox size but just their archive items and sizes.

    1. What I do understand is that you don’t see those columns in Microsoft Excel.

      It can happen when the CSV file is not correctly imported into Microsoft Excel. First, open the CSV file with Notepad and confirm that all values are shown.

      To import the CSV file in Microsoft Excel, follow these steps:

      1. Start Microsoft Excel
      2. Click in the tab on “Data”
      3. Click in the ribbon on “From Text/CSV”
      4. Select the CSV file

  4. I got this error message, how do I fix it?

    Choose The Task: 1
    Get-mailbox : The term ‘Get-mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    and try again.
    At line:117 char:15
    + $AllMailbox = Get-mailbox -resultsize unlimited
    + ~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    1. You get this error because you are running the script from PowerShell/PowerShell ISE.
      For options 1-5, run Exchange Management Shell and run the script.

  5. I get this messege in Exchange online:

    Method invocation failed because [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] does not contain a method named ‘ToMB’. At C:\Scripts\Mailboxsize1.ps1:192 char:1 + $userObj | Add-Member NoteProperty -Name “TotalItemSize” -Value $Stat … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (ToMB:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound

    1. You get this message because you are running option “2.Export to CSV File”. Use that option if you want a report for the Exchange on-premises mailboxes. In your case, you want a report for the Exchange Online mailboxes. You need to select option “6.Export to CSV File (OFFICE 365)”.

      These are the steps:

      1. Connect to Exchange Online
      2. Run MailboxSizeReport.ps1 PowerShell script
      3. Select option “6.Export to CSV File (OFFICE 365)”
      4. Insert export path

  6. x\thank you a lot .

    can we schedule it in task scheduler with attributes 2 of exporting and constant shared location ?

  7. Hello, Ali.
    Thank you for this script.
    I’d like to understand why did you use the BigFunnelMessageCount instead of the ItemCount when counting archive messages?

Leave a Reply

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