M365-004 · Script
Exchange Mailbox Inventory and Usage
Lists every Exchange Online mailbox with size, item count, quota use, archive, holds, forwarding and last activity.
Version 1.0.0Language PowerShellUpdated November 2026Report only, changes nothing
What it does
Read-only. Saves a dated CSV in the Reports folder. Flags mailboxes that are:
- Near quota: at or above -WarnPercent of the send quota
- Inactive: no user activity in -InactiveDays days
- Forwarding: forwarding is set on the mailbox
Archive sizes are included with -IncludeArchive (slower).
Requirements
ExchangeOnlineManagement module, installed by you from the PowerShell Gallery (not included). App registration with Exchange.ManageAsApp and a role that can read mailboxes (for example View-Only Recipients or Exchange Administrator). Windows PowerShell 5.1 or PowerShell 7.
How to run it
- Run from: an admin workstation or scheduled task with the Microsoft modules installed and app sign-in configured
- This is an admin script for your Microsoft 365 tenant, not a per-device endpoint script
- User interaction: none with app-only sign-in
- Schedule: run on demand, or weekly for reports
Settings
| Name | What it does | Options | Default |
|---|---|---|---|
| WarnPercent | Percent of the send quota that counts as near full. Default: 90. | 90 | |
| InactiveDays | Days without user activity before a mailbox is flagged Inactive. Default: 90. | 90 | |
| IncludeArchive | Also report archive mailbox sizes. | False | |
| AlertOnNearQuota | Exit 1 when any mailbox is near quota. | False | |
| ClientId | Application (client) ID of your app registration. | ||
| CertificateThumbprint | Thumbprint of the certificate uploaded to the app registration. | ||
| Organization | Your tenant's onmicrosoft.com name, for example contoso.onmicrosoft.com | ||
| UseExistingSession | Use an Exchange Online session you already opened with Connect-ExchangeOnline. | False |
Exit codes
- 0 = Completed
- 1 = Mailboxes near quota (only with -AlertOnNearQuota)
- 2 = Script error (see log)
Testing steps
- Run it on one test tenant or small OU and check the output and log.
- Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
- Roll out to a small group next, then everyone.
Rollback steps
Report only. It saves a CSV and changes nothing else.
Version and change log
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | November 2026 | First release. |