PowerShell: Update folders (delete/purge, or add/delete properties) No ratings yet.


Please note: the script has now been moved to https://gallery.technet.microsoft.com/exchange/PowerShell-Update-mailbox-79fd411a.

This script allows you to update folders by adding or removing properties.  You can also use the script to purge or delete the folders.

To delete properties from a folder:

.\Update-Folders.ps1 -Mailbox 1@e14.local -FolderPath “\Folder 1” -ProcessSubFolders -DeleteFolderProperties @(“0x36160102”, “0x36DA0102”)

In the above example, MAPI properties 0x36160102 and 0x36DA0102 will be deleted from Folder 1 (which is at the same level as Inbox i.e. a subfolder of the mailbox root message folder) and all subfolders.

To add properties to a folder:

.\Update-Folders.ps1 -Mailbox 1@e15.local -FolderPath “Inbox\Test” -AddFolderProperties @{“0x3004001F” = “This is the folder comment”}

In the above example, a folder comment is added to the folder Test which is found in the Inbox.

Note that -DeleteFolderProperties requires an array (or some other enumerable list) as input, so is defined above with normal () bracket.  -AddFolderProperties requires a hash table (a dictionary object would also work), so is defined with curly brackets {}.

Script parameters:

 -Mailbox  The mailbox to be processed (if missing, current user’s mailbox is assumed, though this will only work in a domain environment).
 -PublicFolders  If this switch is present, public folders will be processed.
 -Archive  When specified, the archive mailbox is accessed (instead of the main mailbox).
 -FolderPath  If specified, processing will start from the named folder.  If not specified, the message root folder (or public root) is assumed.
 -ProcessSubfolders  When specified, subfolders will also be processed.
 -AddFolderProperties  Adds the given properties (must be supplied as hash table @{}) to the folder(s).
 -DeleteFolderProperties  Deletes the given properties from the folder(s).
 -Delete  Deletes the folder(s) – this will only work if they are empty.
 -Purge  Purges (empties) the folder(s).  This parameter is required if you want to delete folders that have messages in them.
 -Credentials  Credentials used to authenticate with EWS.
 -Username  Username used to authenticate with EWS.
 -Password  Password used to authenticate with EWS.
 -Domain  Domain used to authenticate with EWS.
 -Impersonate  Whether we are using impersonation to access the mailbox.
 -EwsUrl  EWS Url (if omitted, then autodiscover is used).
 -EwsManagedApiPath  Path to managed API (if omitted, a search of standard paths is performed).
 -IgnoreSSLCertificate  Whether to ignore any SSL errors (e.g. invalid certificate) – use with care.
 -AllowInsecureRedirection  Whether to allow insecure redirects when performing autodiscover.
 -LogFile  Log file – activity is logged to this file if specified.
 -Trace  If specified, EWS requests/responses will be dumped to the standard output (usually console)

Please rate this

Leave a Reply

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