Microsoft 365

Office 365 | Exchange Online: List inactive Mailboxes

Retired employees are usually reported to the IT department, but for whatever reason this is not always the case. As an Office 365 administrator, you might want to know which user haven’t logged in for a long time to tidy up your Office 365 environment and remove the orphaned user mailboxes. That’s what this blog post is about. Have fun reading.

Login to Exchange Online

You’ll net three PowerShell commands to log into Exchange Online, as described here:

$UserCredential = Get-Credential

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

Import-PSSession $Session -DisableNameChecking

For your convenience, I’ve created a function that enables you to login with only one command. Interested? Have a look: Office 365 Exchange Online PowerShell: Quick connect with Connect-ExchangeOnline

To make sure you are actually logged in Exchange Online, run an exchange specific command like Get-Mailbox.



We are ready. Let’s move on.

Determine inactive Mailboxes

So, let’s examine all users with mailboxes that haven’t logged on in the last 10 days with the following PowerShell code:

Get-Mailbox –RecipientType 'UserMailbox' | Get-MailboxStatistics | Sort-Object LastLogonTime | Where {$_.LastLogonTime –lt (Get-Date).AddDays(-10) } | Select-Object DisplayName, LastLogonTime


Nice one.

Normally, you will search for users who have not logged in for a long time. For that simply replace -10 with a value of your choosing.

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.