See which shared mailboxes are above 50GB and need a license in Exchange Online with PowerShell

shared mailboxes receive a maximum of 50GB when no license is assigned.

Microsoft has always said that a shared mailbox can be up to 50GB unless you have assigned a license.
This is not the case in most tenants and this has always been tolerated by Microsoft.
Now they are really going to force this by capping shared mailboxes at 50GB that do not have a license.

Here is the link for Exchange Online limits, including Shared Mailbox capacities.

A PowerShell script to check if you have Shared Mailboxes above 50GB.

So, to make sure that your shared mailboxes in Exchange Online do not reach their limit, I have created a script that can check if you are close to the limit of 48GB.

The script below checks with the mailbox statistics whether the size is KB, MB, or GB. If it is GB, it checks if the mailbox is over the 48 GB.

When the Mailbox is over the 48Gb, you will see a MAILBOX LIMIT IS REACHED in the $data object. And you can also export the $data to a CSV.


I assume in the script that you are an administrator in Exchange Online, and that you already have the Exchange Online module installed.
The PowerShell module for EXO can be found here.

Using PowerShell for Exchange Online.

The script needed to log in to Exchange Online.
Copy / paste it into PowerShell.

$cred365 = get-credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $cred365 -Authentication Basic -AllowRedirection

Import-PSSession $Session

The Script.

You can also download the script from
Click here for the downloadable link.

$data = @()

$mbxs = get-mailbox -ResultSize unlimited -filter {recipienttypedetails -eq "sharedmailbox"}

foreach ($mb in $mbxs)


    $dataobject = new-object psobject

    $stats = Get-MailboxStatistics -Identity $mb.UserPrincipalName

    $dataobject | add-member -NotePropertyValue $MB.userprincipalname -NotePropertyName UserPrincipalName

    $dataobject | add-member -NotePropertyValue $mb.displayname -NotePropertyName Displayname

    $dataobject | add-member -NotePropertyValue $stats.totalitemsize -NotePropertyName Totalsize

    switch -Wildcard ($stats.totalitemsize.value)




            $totalitemsize = $stats.TotalItemSize.Value -replace " GB*"

            $totalsize = $totalitemsize.Split(" ")[0]

            if ( [math]::Round($totalsize, 3) -gt 48)


                $dataobject | add-member -NotePropertyValue "MAILBOX LIMIT IS REACHED" -NotePropertyName "Mailbox Limit"




                $dataobject | add-member -NotePropertyValue "Mailbox is ok" -NotePropertyName "Mailbox Limit"





            $dataobject | add-member -NotePropertyValue "Mailbox is ok" -NotePropertyName "Mailbox Limit"




            $dataobject | add-member -NotePropertyValue "Mailbox is ok" -NotePropertyName "Mailbox Limit"



    $data += $dataobject


$data | export-csv C:\temp\totalitemsize_SMBX-V2.csv -NoTypeInformation


If you have any questions about this script, you can leave a comment.

A little extra

This post contains PowerShell. Would you like to learn the basics better? I have created a new website to learn basic PowerShell in an ’emulator’ environment.
Click here to go learn Basic PowerShell.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell Automation Engineer @ Wortell.

One thought on “See which shared mailboxes are above 50GB and need a license in Exchange Online with PowerShell”

  1. PS C:\WINDOWS\system32> foreach ($mb in $mbxs)
    >> Repost error – And export in blank excel.csv

    No linha:1 caractere:23
    + foreach ($mb in $mbxs)
    + ~
    Corpo de instrução ausente no loop foreach .
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingForeachStatement

Leave a Reply

Your email address will not be published. Required fields are marked *