Monday, June 9, 2014

Find all inactive mailboxes in Exchange 2010 or 2013 environment

How to find all inactive mailboxes in Exchange 2010 or 2013 environment?
OR
How to get the list of all mailboxes which are not accessed in last X days?
You can get the list of all the mailboxes which are not accessed in last 90 days by using below cmdlet on the screen.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where{$_.Lastlogontime -lt (Get-Date).AddDays(-90)} | Select DisplayName, LastLoggedOnUserAccount, LastLogonTime

Change the days from 90 to 180, 365 or whatever you want in AddDays(-90).
You can export the result to csv file by adding pipe to Export-CSV

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

Now question is, how to get the list of all mailboxes which are not accessed at all? Use below cmdlet to get the list.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where{$_.Lastlogontime -eq $Null} | Select DisplayName, LastLogonTime | Export-csv C:\Temp\InactiveUsers.csv

But using above cmdlet you may find that list includes all the mailboxes which are created recently and new users/employees of your company might be joining the firm in future date. In that case we can add a column to find out when the mailbox is actually created so you would be able to filter those mailboxes.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where{$_.Lastlogontime -eq $Null} | Select DisplayName, LastLogonTime, @{Name=”WhenMailboxCreated”;Expression={(Get-Mailbox $_).WhenMailboxCreated}} | Export-csv C:\Temp\InactiveUsers.csv 

No comments:

Post a Comment