Powershell – Find Stale/Inactive Exchange Mailboxes

emailemail-serverexchangeexchange-2010powershell

Hoping someone can help with this/it's an easy to explain issue, but basically I'm looking to find mailboxes in our Exchange 2010 environment that haven't been logged into for more than x days/a certain amount of time.

I've found several powershell scripts online which would/should seem to work by looking at the last logon time attribute for mailbox statistics, but when I try to export (or even just display the results in powershell), there seems to be a lot of mailboxes (but not all) that do not show any information for lastlogontime – it's just blank.

One of the scripts I used for example is below, but wondering if anyone has maybe a better way of finding this information or knows why these results aren't being generated as expected? Thank You in advance for any help you can offer!

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where{$_.Lastlogontime -lt (Get-Date).AddDays(-90)} | Select DisplayName, LastLoggedOnUserAccount, LastLogonTime | Export-csv C:\Temp\InactiveUsers.csv

Best Answer

Last Logon time being blank usually means it hasn't been used at all. However I personally would adjust the script to remove the requirement for the time limit

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName, LastLoggedOnUserAccount, LastLogonTime

Then export those results to CSV and sort the results by the dates involved. That will give you a better idea if the results you are getting back are expected.

This script on the TechNet gallery would give you better results though. https://gallery.technet.microsoft.com/scriptcenter/List-Inactive-Mailboxes-on-1ac82ddf as it is based on the last sent item, rather than logon date. If you have a BES or other product that scans the mailboxes then the logon date can be very inaccurate.