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.


Intro

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 https://outlook.office365.com/powershell-liveid/ -Credential $cred365 -Authentication Basic -AllowRedirection

Import-PSSession $Session

The Script.

$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)

    {

        "*GB*"

        {

            $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"

            }

            else

            {

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

            }

        }

        "*MB*"

        {

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

        }

        "*KB*"

        {

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

        }

    }

    $data += $dataobject

}

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

Summary

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

My name is Bas Wijdenes and I work full-time as a Services Engineer. In my spare time I write about the error messages that I encounter during my work. Furthermore, I am currently occupied with Azure, Office 365, and PowerShell for automating daily tasks.

Leave a Reply

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