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

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!





Carol Kang October 23, 2012 at 3:48 pm
This looks to be a good resource.
Rajith Enchiparambil October 24, 2012 at 6:31 am
Thanks Carol.
Rusty Shackleford October 24, 2012 at 1:10 am
Be sure to exclude resource mailboxes if you decided to indiscriminately delete mailboxes because they have not been logged into for awhile.
Rajith Enchiparambil October 24, 2012 at 6:33 am
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.
Saiyan December 25, 2012 at 3:19 pm
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.
Rajith Enchiparambil February 1, 2013 at 8:39 am
Get-Mailbox –Org “org name” | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogontime