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!
I have a large number of mailboxes (80K or so). when I run these commands for user only, it ends up with a memory error and I only end up getting a fraction of the MBX’s in the export. How can I run the command in a way where it splits up the dumps or will create however many exports is needed to complete? It works fine for a smaller number of mailboxes… just not the total.
Hi Mike,
Why not run the command against servers rather than everyone? And maybe loop it to go through all servers in a script & dump the output.
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.
Get-Mailbox –Org “org name” | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogontime
It only gives 1000 results. what modification I could do to get all the results
Use the -Resultsize Unlimited in the command Shubhangni
Be sure to exclude resource mailboxes if you decided to indiscriminately delete mailboxes because they have not been logged into for awhile. :)
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.
This looks to be a good resource.
Thanks Carol.