Skip to main content

Posts

Showing posts from March, 2013

Removing attachments of a specific type with EWS and Powershell

Sometimes particular attachments can create different issues for a number of different reasons so you might find you want to get rid of all those attachments without removing the messages they are attached to. If you find yourself in this situation then this is the sample for you. Firstly to find the attachments of a specific type we use the following AQS query System.Message.AttachmentContents:.pdf This acts as a first level filter but it will give a few false positives so a second client level check of the actual Attachment file name is needed. foreach  ( $Attachment   in   $Item .Attachments)   {                 if ( $Attachment  -is [Microsoft.Exchange.WebServices.Data.FileAttachment]){              if ( $Attachment .Name.Contains( ".pdf" )){             }                }     }   The following script can be run in one of two modes , Report will just report on attachments that are found in a particular folder and Delete will delete attachments fr
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.