Skip to 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 Exchange Server/Exchange Online. Before doing that, find all the users’ mailbox sizes in Exchange Server/Exchange Online. The script that we will use to display or export mailbox statistics 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 Exchange Online (Microsoft 365/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. If you don’t have a scripts folder, create one.

Ensure the file is unblocked to prevent errors when running the script. Read more in the article Not digitally signed error when running PowerShell script.

Get mailbox size all users Exchange PowerShell scripts folder

Run Exchange Management Shell or Connect to Exchange Online PowerShell. 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 all users Exchange PowerShell exported CSV

Open mailbox size report with Microsoft Excel

To import all the Mailbox Size Report data from CSV file into Microsoft Excel, follow these steps:

1. Start Microsoft Excel and open a new blank workbook.

2. Select Data > From Text/CSV.

Get mailbox size all users Exchange PowerShell import data from Text/CSV

3. Select the CSV file and click on Import.

Get mailbox size all users Exchange PowerShell import CSV into Excel

4. Check that all the columns are visible.

5. Verify that TotalItemSize is available and click on Load.

6. The Report.csv is loaded in Microsoft Excel.

Get mailbox size all users Exchange PowerShell in Excel

7. Sort the column TotalItemSize from largest to smallest size.

Get mailbox size all users Exchange PowerShell sort TotalItemSize

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

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.ps1 PowerShell script to list the mailbox size for all users in the organization. It’s a great script, and you should use it 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 29 Comments

  1. When I ran this script, I received below error
    Method invocation failed because [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] does not contain a method named ‘ToMB’.
    At C:\Users\XXXXXX\Reports\Mailboxsizereports.ps1:124 char:17
    + … $userObj | Add-Member NoteProperty -Name “TotalDeletedIte …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (ToMB:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

  2. Hi Ali,

    Thanks so much for this – it’s a great resource.

    In the CSV output, the TotalItemSize is displayed as GB, MB and Bytes, depending on the total size. This makes sorting and filtering difficult. Is there any way to get it to output only in bytes or MB?

    The following expression has worked to achieve similar, but I am not sure it could be implemented in your script

    Expression={[math]::Round(($_.FolderSize.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),0)}}, ItemCount

  3. I am looking for such more information like department , title enable or not, last login etc. can we add these kind of information in it ?

  4. Hello Mr. Ali Tajran,

    I’m having the same problem as Ab.
    On one MSExch19 server I get complete CSV with Task2 as expected, on another I get missing TotalItemSize,ItemCount,DeletedItemCount and TotalDeletedItemSize columns .

    I tried Task1 as test and it shows correctly.
    I believe the problem is somewhere with variable $Stats on line 85, because I think on line 120 the variable resolves to null.
    Unfortunately when I run the commands in EMS $Stats populates okay, so I am stumped at how to solve this.
    Any idea why’s this happening or how to solve it, or what I could try to find out?

    Anyway, as this is the first time I am commenting – thank you very much for clear and educational website as this!

    Regards,
    Zdražilová

    1. Open the CSV file with Notepad and verify.

      I tested both tasks 1 and 2 right now on a couple of Exchange Server 2019 servers. Everything works fine and the report shows all columns and values.

  5. Hi Ali,
    Thank you for your effort making this article.
    if you may help, can we make this automate via task scheduler and send the csv file via email?

    thank you

  6. Hi Ali,

    Great website, wonderful resources! I’m using the script in Exchange 2016, I have 121 users. The total itemsize is blank in the CSV. Any ideas? I’m on the latest CU version with all updates.

    Thanks in advance,

    Ab

    1. Only the TotalItemSize? Or more columns?

      Open the CSV file with Notepad and check if the values appear. I tried it right now, and everything works. Most likely, this has to do with the CSV file import.

      If you go through the exact steps, you will not have any issues.

  7. Good day,
    The script works well, thank you. Was wondering if it can be altered to specify a date range for the mailbox and archive mailbox size

  8. Hello ALI,

    Your blog is excellent which saves our time on activities.
    In this script if I want to find the AccountDisabled Status, please can you help me to add as I need to find the AccountDisabled for all the mailboxes as I am working on mailbox consolidation.

    Regards
    Anand Sunka

  9. Hi,
    How can script give the results in KB and not in MB ? Where can I put the “=convertto KB” ?
    In rest this script work very well.

  10. 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.

  11. 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

  12. 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 PowerShell
      2. Run MailboxSizeReport.ps1 PowerShell script
      3. Select option “6.Export to CSV File (OFFICE 365)”
      4. Insert export path

  13. thank you a lot.

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

  14. 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 *