This PowerShell script can be used to purge a folder of its contents, optionally only deleting items before a certain date.
.\Purge-MailboxFolder firstname.lastname@example.org “Test Folder” “02/Aug/2013” -Impersonate -SearchForFolder
The above will search for the first folder called Test Folder in the mailbox of email@example.com, and when found it will delete all messages dated before 2nd August 2013. It uses impersonation to access the mailbox.
Full parameter details:
Purge-MailboxFolder -Mailbox <string>
[-Username <string> -Password <string> [-Domain <string>]]
-Mailbox : Mailbox SMTP email address (OR filename for source list of mailboxes; text file, one mailbox per line)
-Folder : Folder to be purged (items within it deleted). Full path must be specified if SearchForFolder parameter is missing.
-PurgeBeforeDate : The date before which items will be deleted from the folder
-SearchForFolder : If present, the mailbox will be searched for until the named folder is found
-Username : Username for the account being used to connect to EWS (if not specified, current user is assumed)
-Password : Password for the specified user (required if username specified)
-Domain : If specified, used for authentication (not required even if username specified)
-Impersonate : If set, impersonation will be used
-EwsUrl : Forces a particular EWS URl (otherwise autodiscover is used, which is recommended)
-IgnoreSSLCertificate : If set, any SSL errors will be ignored
-EWSManagedApiPath : Filename and path to the DLL for EWS Managed API (if not specified, paths are searched)