How to Discover Unused Mailboxes
In Exchange 2007, and later, we can use the Get-MailboxFolderStatistics cmdlet to retrieve information about the folders in a specified mailbox, including the number and size of items in the folder, the folder name and ID, and other information.
If we add the IncludeOldestAndNewestItems switch parameter, Get-MailboxFolderStatistics will also return the dates of the oldest and newest items in each folder. Using that information we can determine the last time a message was sent from a mailbox.
Using the script below, we can get all user mailboxes that did not sent an email in the last X days. To make the script run faster, we will process just the SentItems folder (using the FolderScope parameter). Note that items in folders are stamped with a GMT time so we use the ToLocalTime() method to convert the value to local time.
$xDays = 60
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Foreach-Object {
$si= Get-MailboxFolderStatistics $_ -IncludeOldestAndNewestItems -FolderScope SentItems
if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays)
{
$_
}
}