/flags/exchange-online/get-exomailbox-resultsize-unlimited
Get-EXOMailbox -ResultSize Unlimited: return more than 1000 mailboxes
- tool
- Exchange Online PowerShell
- command
- Get-EXOMailbox
- flag
- -ResultSize
- default
- 1000
Get-EXOMailbox -ResultSize Unlimited returns every mailbox that matches the query. Without the parameter, the cmdlet stops after 1000 results: the reference says "The ResultSize parameter specifies the maximum number of results to return. If you want to return all requests that match the query, use unlimited for the value of this parameter. The default value is 1000." In any tenant with more than 1000 mailboxes, a report without it is silently incomplete.
Connect-ExchangeOnline -UserPrincipalName admin@contoso.com
Get-EXOMailbox -ResultSize Unlimited | Measure-Object
Get-EXOMailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited |
Select-Object DisplayName, PrimarySmtpAddress |
Export-Csv shared.csv -NoTypeInformationAccepted values
The parameter type is Unlimited[UInt32]: either the word Unlimited or a whole number from 0 to 4294967295. Checked offline in Windows PowerShell 5.1 with ExchangeOnlineManagement 3.10.1, before any connection:
Import-Module ExchangeOnlineManagement
$t = (Get-Command Get-EXOMailbox).Parameters['ResultSize'].ParameterType
"Type: " + $t.Name + " of " + $t.GenericTypeArguments[0].Name
$u = [System.Management.Automation.LanguagePrimitives]::ConvertTo('Unlimited', $t)
"'Unlimited' -> IsUnlimited=" + $u.IsUnlimited
$n = [System.Management.Automation.LanguagePrimitives]::ConvertTo('5000', $t)
"'5000' -> IsUnlimited=" + $n.IsUnlimited + ", Value=" + $n.Value
try { Get-EXOMailbox -ResultSize all -ErrorAction Stop } catch { $_.Exception.Message }
try { Get-EXOMailbox -ResultSize Unlimited -ErrorAction Stop } catch { $_.Exception.Message }Output
Type: Unlimited`1 of UInt32 'Unlimited' -> IsUnlimited=True '5000' -> IsUnlimited=False, Value=5000 Cannot bind parameter 'ResultSize'. Cannot convert value "all" to type "Microsoft.Exchange.Management.RestApiClient.Unlimited`1[System.UInt32]". Error: "Input string was not in a correct format." You must call Connect-ExchangeOnline before calling any other cmdlet.
The value is case-insensitive (unlimited works). Words such as All or -1 are rejected when the parameter is bound, before the cmdlet contacts the service; a valid value without a session fails with You must call Connect-ExchangeOnline before calling any other cmdlet.
| Value | Result |
|---|---|
| (not specified) | at most 1000 objects |
| -ResultSize 50 | at most 50 objects, useful for testing a report |
| -ResultSize Unlimited | all matching objects |
| -ResultSize All or -1 | binding error: the value cannot be converted |
Pitfalls
- Combine it with a filter.
-ResultSize Unlimitedwith no filter downloads every mailbox. Use-Filter "Department -eq 'Sales'"or-RecipientTypeDetails UserMailboxso the service does the narrowing. - Ask only for the properties you need. Get-EXOMailbox returns a minimum property set by default; add the few you need with
-Propertiesor a property set with-PropertySets(-PropertySets) instead of-PropertySets Allover the whole tenant. - Same rule in other cmdlets.
Get-Mailbox,Get-RecipientandGet-EXORecipientalso default to 1000; see Get-EXOMailbox vs Get-Mailbox. - Permissions. The account needs an Exchange role that includes the cmdlet, such as View-Only Recipients, or the Exchange Administrator role in Microsoft Entra ID.
FAQ
Why does Get-EXOMailbox return exactly 1000 mailboxes?
1000 is the documented default of -ResultSize. Add -ResultSize Unlimited to return every mailbox that matches, or a number to set another limit.
Is -ResultSize Unlimited slow in large tenants?
Get-EXOMailbox pages through the REST API, so it scales well, but returning tens of thousands of objects still takes time and memory. Add -Filter or -RecipientTypeDetails so the service returns only what you need, and request only the properties you use.
Does Get-Mailbox use the same parameter?
Yes. Get-Mailbox, Get-Recipient and most Get- cmdlets in Exchange Online also stop at 1000 results by default and accept -ResultSize Unlimited.