Report Last Logon Time for Mailboxes in Exchange Online

Most customers will find it helpful to know who is and isn’t using their Exchange Online mailbox. I have yet to find a built in report in Office 365 that provides similar info. And when it comes to licensing services in Office 365 it is important to identify areas where costs may be reduced.

The commands below will provide a list of mailboxes logged in to older than a specific number of days. The first is a basic on screen list of mailboxes that haven’t been logged in to for over 90 days. The second exports data to a CSV file in which can be reviewed as you wish.



First, we need to Connect to Office 365 with PowerShell.



Second, type this command to display a oldest date sorted list of mailboxes not accessed in over 90 days. The number of days (in red) can be modified to whatever number value is needed.

Get-Mailbox -RecipientType 'UserMailbox' | Get-MailboxStatistics | Sort-Object LastLogonTime | Where {$_.LastLogonTime –lt ([System.DateTime]::Now).AddDays(-90) } | Format-Table DisplayName, LastLogonTime


The information will look similar to this…



If the command returns no data, decrease the number of days to search.



If reviewing a report of mailboxes last logged on to in Excel (or similar) is preferred, use this command. Be aware that all mailbox statistics are exported to CSV and that the DisplayName and LastLogonTime columns will be the center of focus. Again, change the number as needed as well as the location/name of the report that works for you. Finally, review in your preferred CSV viewer.

Get-Mailbox -RecipientType 'UserMailbox' | Get-MailboxStatistics | Sort-Object LastLogonTime | Where {$_.LastLogonTime –lt ([System.DateTime]::Now).AddDays(-90) } | Export-Csv "X:\REPORTS\MAILBOXSTATS_REPORT.CSV" -NoTypeInformation



These same commands will work for an on premise environment as well.

Good luck and have fun!


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 )

Google photo

You are commenting using your Google 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