title: Powershell - Export inactive mailboxes Exchange 2010
body: <p>I'm looking to run a script like this and export to a CSV and sort by the last time the mailbox was used.
  Basically we're trying to find mailboxes that haven't been used for more than 60 days. Once we load the list, we will run the script again except add a bit of code to export each mailbox to PST (I'm not sure how to do that portion, either)</p>
  
  <p>The mailboxes were recently migrated from Exch 2007.
  The mailboxes are backed up on a daily basis, so access time won't work.</p>
  
  <p>I was looking at something like the below, but I get an error that it cannot get-mailboxstatistics from a mailbox on a server running version 8 while the script is running on version 14. This is likely because there are a large number of mailboxes we left on an Exchange 2007 server which are all terminated users. I would like to include these in the search results.</p>
  
  <pre><code>$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) 
  { 
  $_ 
  } 
  
  } 
  </code></pre>