Tuesday, January 31, 2017

Delete all Exchange mailbox content using PowerShell

This can be a useful script for anyone who has the need to delete the entire contents of an Exchange mailbox. We have some test accounts that can get overridden with emails if they're not cleaned out. This script prints out a summary of how many items are in the mailbox and then deletes them all. It was tested against Exchange server 2013.

$id = "user@acme.com"

#See how many items are in mailbox
Get-MailboxFolderStatistics $id | Select Identity, ItemsInFolder

#Delete items in mailbox
Search-Mailbox -Identity $id -DeleteContent -force