Share via


Checking mailbox Recoverable Deleted Items Script

Yesterday I was at a customer and they ran into an issue while migrating from Exchange 2007 to Exchange 2010. They were using a batch mailbox move script that set retention policies on the mailboxes as they moved to Exchange 2010. Unfortunately, the script was used incorrectly at one point and they applied the wrong retention policy to a group of users they migrated. The impact was that these mailboxes had all of their items older than 90 days put into recoverable deleted items and they weren't supposed to. Now, they didn't necessarily know which batch of moves were impacted, so they asked me to build a script to best identify the impacted mailboxes. They weren't sure post-migration which of these mailboxes should not have had the policy applied, so they couldn't just look at the retention policy itself.

How I built the script, was to have them provide a list (in a text file) of each batch of user migrations, then I would find the problem users based on the size of their recoverable deleted items (the users that it was supposed to apply to shouldn't have had that much for the retention policies to effect because they already had a policy on Exchange 2007 that was working). This allowed us to find which users were truly effected, then either restore their mailbox in Exchange 2007 and migrate again or just select all the user's recoverable deleted items and restore.

I've attached the script, but if you would like just copy and paste to a text file and rename to .ps1, you can do that with the below:

#Author: Aaron Calloway
#Use this script to get the size and item count of the items in user's recoverable items
#Usage: When prompted for input file, type the full path of file location. i.e. "C:\temp\userlist.txt"
#When prompted for the output file, type in the full path of where you want the file to be located.
#i.e. "C:\temp\recoverableitemslist.txt"
#
#Note:This script APPENDS data, so it will not overwrite an existing file, it will add to it.
#
#
#
$ip_file=Read-Host "Where is the input file located?"
if (! $ip_file){
Write-host -Foregroundcolor "Red" "You must select an input file!"

$ip_file = Read-Host "Where is the input file located?"
}

$Users=(Get-Content -Path $ip_file)

$op_file = Read-Host "Which file would you like the results written to?"

if (! $op_file){
Write-Host -Foregroundcolor "Red" "You must select an output file!"

$op_file = Read-Host "Which file would you like the results written to?"
}

foreach ($user in $users) {Get-MailboxFolderStatistics $user |? {$_.FolderType -eq "RecoverableItemsDeletions"}|select identity,foldertype,folderpath,itemsinfolder,foldersize | Out-File $op_file -append}
Write-Host -Foregroundcolor "Green" $users.count "Users Completed. File is located at $op_file"

 

Get_RecoverDeletedItems.ps1