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: https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps


$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -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.


Get-Mailbox

4.png

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

5.png

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:

WordPress.com Logo

You are commenting using your WordPress.com 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.