You want to create mailboxes in Exchange Online and use Office 365. Before you can…
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.
Table of contents
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:
- Exchange on-premises: Run Exchange Management Shell as administrator.
- Exchange Online (Microsoft 365/Office 365): Run PowerShell as administrator and connect to Exchange Online PowerShell.
The MailboxSizeReport.ps1 PowerShell script got 7 options:
- Display in Exchange Management Shell
- Export to CSV File
- Export to CSV File (Specific to Database)
- Enter the Mailbox Name with Wild Card (Export)
- Enter the Mailbox Name with Wild Card (Display)
- Export to CSV File (OFFICE 365)
- 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:
- Display Name
- Alias
- SamAccountName
- RecipientType
- Recipient OU
- Primary SMTP address
- Email Addresses
- Database
- ServerName
- TotalItemSize
- ItemCount
- DeletedItemCount
- TotalDeletedItemSize
- ProhibitSendReceiveQuota-In-MB
- UseDatabaseQuotaDefaults
- LastLogonTime
- ArchiveName
- ArchiveStatus
- ArchiveState
- ArchiveQuota
- ArchiveTotalItemSize
- 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 »
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.
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.
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.
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
Thank you for the script.
However, I ran optin 4 because I want to export just one domain and I get the same error as Bojan:
does not contain a method named ‘ToMB’
Is there a way to fix this, I cannot run a full export because our Tenant is almost 60K mailboxes and it will take for ever to run a full export
Thank you
Hello Ali,
Thank you for this script.
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.
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
Hi Norafify,
The total count shows in MB, which means that the example of yours is as:
240 MB
9731 MB
26117 MB
Hi, i only get a lot of errors, when i try to run the script.
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.
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
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
Hi,
Could you help me with a script to export archive size too?
Thank you
Hi Mo,
The script already has that feature. The export will show the archive size in the column ArchiveTotalItemSize.
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.
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
I find the same problem when choosing option 2 to export to CSV. Appears the “if($Stats)” must be returning a false value so those attributes aren’t getting added. When I choose option 1 to display, all but a few mailboxes DO have statistics, though. Perhaps it has something to do with the first mailbox that’s returned happening to be one that does not have statistics.
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
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.
Tnx Dear Ali
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
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
x\thank you a lot .
can we schedule it in task scheduler with attributes 2 of exporting and constant shared location ?
hi
is possible add if account in active directory is disable or no?
thz
kindly share the script with me
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?