Exchange Online PowerShell
The ExchangeOnlineManagement module connects to Exchange Online. Connect-ExchangeOnline authenticates and imports the cmdlets; Disconnect-ExchangeOnline ends the session.
Documentation: Microsoft Learn
Overview
The first surprise is that Get-Mailbox returns 1,000 results by default. Not an error, not a warning, just the first thousand. -ResultSize Unlimited is required for any real inventory, and forgetting it produces a report that is quietly wrong in a tenant of any size.
The second is filtering. These cmdlets have -Filter, which runs server-side, and it is much faster than Where-Object for large tenants. The syntax is Exchange's own, so it is another dialect to keep straight alongside AD filters and OData.
The third is throttling. Exchange Online limits how fast you can call it, and a tight loop over thousands of mailboxes will be slowed or blocked. Get-Mailbox once and work from the results rather than calling per user inside a loop.
Remember that mailbox size lives in Get-MailboxStatistics, not Get-Mailbox, so a size report needs both, joined on identity. And TotalItemSize is a formatted string rather than a number, so sorting on it directly sorts alphabetically.
For automation, use certificate-based app-only authentication. Basic authentication is gone.
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
[pscustomobject]@{
Connect = 'Connect-ExchangeOnline -UserPrincipalName admin@corp.com'
Query = 'Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, RecipientTypeDetails'
Stats = 'Get-MailboxStatistics -Identity <upn> | Select-Object TotalItemSize, ItemCount'
Close = 'Disconnect-ExchangeOnline -Confirm:$false'
} | Format-List- Stage 1[pscustomobject]@{
Positional values or no named parameters - Stage 2Format-List
Positional values or no named parameters
What happens
This prints the connect, query, stats and disconnect sequence. -ResultSize Unlimited appears in the query line because leaving it out is the single most common error here. The Stats line is separate because size information is not on the mailbox object.
Worth remembering
- Get-Mailbox returns 1,000 by default. Use -ResultSize Unlimited.
- -Filter runs server-side and uses Exchange filter syntax.
- Throttling is real; avoid per-user calls in a loop.
- Mailbox size comes from Get-MailboxStatistics, and TotalItemSize is a string.
Primary documentation
Try it
Illustrative output · values vary by environment
Example reader
Inspect this page's example
Run supported commands against the practice data, or inspect the example without executing it.
Ready to inspect.
Prints the Exchange Online session sequence with the result-size caveat.
Show reference output
Illustrative output · values vary by environment
Connect : Connect-ExchangeOnline -UserPrincipalName admin@corp.com Query : Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, RecipientTypeDetails Stats : Get-MailboxStatistics -Identity <upn> | Select-Object TotalItemSize, ItemCount Close : Disconnect-ExchangeOnline -Confirm:$false
Keep going
Next: SharePoint Online PowerShellCheck your understanding
A mailbox query fails after connecting. Which details belong in your investigation?
Record the exact error, connected tenant, mailbox identity and assigned role. A successful connection does not guarantee access to every mailbox operation.