PowerShell: Purge folder of items over a certain age No ratings yet.

This PowerShell script can be used to purge a folder of its contents, optionally only deleting items before a certain date.

Example usage:

.\Purge-MailboxFolder user1.ex2k10@hybrid.local “Test Folder” “02/Aug/2013” -Impersonate -SearchForFolder

The above will search for the first folder called Test Folder in the mailbox of user1.ex2k10@hybrid.local, 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>
                    -Folder <string>
                    -PurgeBeforeDate <DateTime>
                    [-Username <string> -Password <string> [-Domain <string>]]
                    [-EwsUrl <string>]
                    [-EWSManagedApiPath <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)



Please rate this

Leave a Reply

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