Find Last Logon Time For An Exchange 2010 Mailbox

Share & Comment

I received an email requesting help with a script to figure out the Exchange 2010 mailboxes that haven’t been used for a while. A one-liner in PowerShell will fetch this info (no need of scripts)!

The logic used here is that if a user haven’t logged into a mailbox for a while (unless he/she is on sabbatical or maternity leave), it is safe to assume that the mailboxes can be deleted. But, how can an Exchange admin find this useful piece of info? You guessed it right, using the Exchange Shell ;)

Run the following command to find out the last time it was logged into by a user.

Get-Mailbox –Resultsize Unlimited | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogontime

You can also export the info into a CSV or HTML file.

Get-Mailbox –Resultsize Unlimited | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogontime | Convertto-Html | Out-File c:\Lastlogon.html

LastLogontime in Exchange 2010

You can target on a per database basis if you have too many users in your organization.

Get-Mailbox –Resultsize Unlimited –Database dbname | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogontime

Check for the built-in cmdlets before thinking about scripts. Keep it simple!

Share & Comment
Subscribe for Updates
Never miss a blog post again
About the author: Exchange Architect, Blogger, Husband & Dad. I have been in IT for the last 11 years, with Exchange Server becoming the prime area in the last few years. I am active on TechNet forums & Experts Exchange.

6 comments… add one

  1. Carol Kang

    This looks to be a good resource.

    1. Thanks Carol.

  2. Rusty Shackleford

    Be sure to exclude resource mailboxes if you decided to indiscriminately delete mailboxes because they have not been logged into for awhile. :)

    1. Thanks for the tip Rusty. To take it further, we can use Get-Mailbox -ResultSize Unlimited | Where {$_.RecipientTypeDetails -eq “UserMailbox”} so that it doesn’t pick any resource mailboxes.

  3. Saiyan

    Thanks nice share.. How can i get the last logon details for users under a specific OU? where each OU stands for a specific unrelated domain hosted on my exchange server.

    1. Get-Mailbox –Org “org name” | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogontime

Leave a Comment