Exchange Server 2007

Exchange 2007 : Purge Outbox Script

Exchange 2007 : Purge Outbox Script

I recently cam across an issue where users email was getting ‘stuck’ in their Outbox, despite being sent to the intended recipient. Some users had approx 95% of the mailbox Send limit in stuck email, so this problem was affecting their ability to work.

The following script helped me to identify that approx 4GB of data was stuck in user Outboxes across my Exchange environment. This will genetrate a CSV file containing the Outbox size for every mailbox in the Exchange Org. Save the following code to a ‘.ps1‘ file and call from the Exchange Shell:

$data = @()
foreach($mbx in Get-Mailbox -ResultSize unlimited) { $data += Get-MailboxFolderStatistics $mbx.identity -FolderScope ‘Outbox’ | select @{n=”DisplayName”;e={$mbx.DisplayName}},FolderPath,ItemsInFolder,@{n=”FolderSize(MB)”;e={$_.folderSize.toMB()}}}

$data | sort-object “FolderSize(MB)” –Descending | export-csv c:\Outbox_sizes.csv

Once I had identified the severity of the issue I wrote the following power shell script to purge all user Outboxes, exporting the to a PST file in case of any repercussion, note you will have to create the intended export folder prior to running this scrip. As before, copy the following command into a  ‘ .ps1‘ file and execute from the Exchange Shell:

foreach($mbx in Get-Mailbox -ResultSize unlimited){ Export-Mailbox -Identity $mbx.identity -IncludeFolders “\Outbox” -PSTFolderPath “C:\OutboxExport\” -DeleteContent -BadItemLimit 1000 -confirm:$false }

Leave a Reply

Your email address will not be published. Required fields are marked *