Get Office 365 Mailbox Sizes Fast with PowerShell Script
Get Mailbox Sizes in Office 365 using PowerShell
Managing and monitoring mailbox sizes is a crucial task in any organization, especially in a cloud-based environment like Office 365. PowerShell provides an efficient way to retrieve mailbox sizes, helping administrators identify large mailboxes and take necessary actions. This guide will walk you through the process of getting mailbox sizes in Office 365 using PowerShell.
Prerequisites
Before you begin, ensure you have the following:
- Office 365 admin account with appropriate permissions
- PowerShell 5.0 or later installed on your local machine
- Remote PowerShell module for Exchange Online installed
Connect to Exchange Online PowerShell
To connect to Exchange Online PowerShell, follow these steps:
- Open PowerShell as an administrator.
- Run the following command to import the Exchange Online PowerShell V2 module:
$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
- Import the remote PowerShell session:
Import-PSSession $Session -AllowClobber
Get Mailbox Sizes
Now that you're connected to Exchange Online PowerShell, you can retrieve mailbox sizes using the Get-MailboxStatistics cmdlet. Here's how:
- Run the following command to get mailbox sizes:
Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ItemCount
This command will display the display name, total item size, and item count for each mailbox.
Filter Large Mailboxes
To filter and display only large mailboxes, you can pipe the output to the Where-Object cmdlet. Here's an example that displays mailboxes larger than 50GB:
Get-MailboxStatistics | Where-Object { $_.TotalItemSize -gt 50GB } | Select-Object DisplayName, TotalItemSize, ItemCount
Export Mailbox Sizes to CSV
To export the mailbox sizes to a CSV file for further analysis or reporting, use the Export-Csv cmdlet. Here's how:
Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ItemCount | Export-Csv -Path "C:\MailboxSizes.csv" -NoTypeInformation
Disconnect the Remote PowerShell Session
After you're done, don't forget to disconnect the remote PowerShell session:
Remove-PSSession $Session
Troubleshooting Common Issues
If you encounter any issues, make sure you've entered the correct credentials and that your Office 365 account has the necessary permissions. Also, ensure that you've installed the latest version of PowerShell and the Remote PowerShell module for Exchange Online.
Conclusion
Retrieving mailbox sizes in Office 365 using PowerShell is a powerful and efficient way to manage and monitor your organization's mailboxes. By following this guide, you can easily identify large mailboxes, export the data for further analysis, and take necessary actions to keep your mailboxes healthy and well-managed.