Saturday, October 6, 2012

Delete emails from mailbox/es – Exchange 2007

First Grant all the permission to the mailboxes you are to have empty.
Get-Mailbox "target-username" | Add-MailboxPermission -AccessRights FullAccess -User "my-username"

Put the below command in the a file and save it as a .ps1 file - It will delete all the emails from a mailbox catchall without prompting

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

Get-Mailbox -Identity catchall | Export-Mailbox -DeleteContent  -Confirm:$false


Put the below command in a file and save it it as a  .bat file and schedule it in windows scheduler
Powershell.exe -command "& {d:\scripts\catchallMailDelete.ps1}"


Delete everything: (from all Mailboxes)
Get-Mailbox | Export-Mailbox -DeleteContent

Export everything: (and then delete the mails from the mailbox)
Get-Mailbox | Export-Mailbox -PSTfolderPath "c:\temp" -DeleteContent

Delete Emails with a given sender name:
Get-Mailbox | Export-Mailbox -SenderKeywords -DeleteContent

No comments:

Post a Comment