DCSIMG
How to Discover Unused Mailboxes - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

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)
   {
      $_
   }

}

Comments

MVPsBlog said:

define: the user do not send mail for more than 60 days. ---- $xDays = 60 Get-Mailbox -OrganizationalUnit

# June 24, 2010 6:00 AM

how to find the unused mailbox « xunyangit's Blog said:

Pingback from  how to find the unused mailbox « xunyangit's Blog

# October 25, 2010 5:37 AM

Joe said:

How to get the last sent item date stamp also in the output . Possibly to export to csv.

# November 1, 2010 1:50 PM

ScriptFanatic said:

Joe, try with this:

  if($si.NewestItemReceivedDate -AND (New-TimeSpan $si.NewestItemReceivedDate.ToLocalTime()).Days -ge $xDays)

  {

     New-Object PSObject -Property @{

         Name = $_.Name

         Alias=$_.Alias

         Server = $_.Server

         LastSentItemDate = $si.NewestItemReceivedDate        

     }

  }

# November 2, 2010 5:39 PM

Sparks said:

Excellent Information

# February 16, 2011 2:34 PM

Abhishek said:

Where does the result get saved ?

# August 24, 2011 6:20 PM

ScriptFanatic said:

@Abhishek, the result is written to the pipeline. You can save it to a variable, redirect it to a file, export it to a csv file, pipe it to another cmdlet...

# August 25, 2011 1:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: