Get the Number of Mailboxes in Office 365

The following is a quick guide on how to get a count of the number of mailboxes in Office 365 for user mailboxes, room mailboxes and shared mailboxes.

Open an administrator powershell

$UserCredential = Get-Credential

The above command should trigger a prompt for a username and password, enter the details of an Office 365 administrator.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/-Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

Now use one of the following commands in powershell:
Retrieve number of user mailboxes:

(Get-Recipient -RecipientTypeDetails usermailbox -ResultSize Unlimited).count

Retrieve number of shared mailboxes:

(Get-Recipient -RecipientTypeDetails sharedmailbox -ResultSize Unlimited).count

Retrieve number of room mailboxes:

(Get-Recipient -RecipientTypeDetails roommailbox -ResultSize Unlimited).count