Skip to main content


Showing posts from June, 2009

Simple Exchange Email client for Powershell using the EWS Managed API

** Updated download to fix issue with 2010 SP1, self signed certs and search *** One thing that is useful now and again when you are testing different problems and configurations on Exchange is to have a Mail client that isn’t Outlook or OWA. Back in the days there used to be a Simple Mapi client called the Exchange client which disappeared after 5.0. While this isn’t a attempt to replace it or to be an end user mail client at all it’s a great little test bench script that allows you to get in and look at mailbox and the items in that mailbox, Download attachments,export single emails, look at Message headers, search for emails and if there is any particular problem you want to tackle in regards to certain properties it’s something that can be very easily adapted to fit an specific problem. How it works This script presents a Winform GUI that allows you to interact with a mailbox and present it into a displayable view back to a user. Okay I could go on like this all day (seriously!!) t

Using SearchFilter and other Nested Types in the EWS Managed API from Powershell

A SearchFilter in the EWS Managed API gives you the ability to place restrictions on any findItem operations you do on a folder with Exchange Web Services. For instance you can search for a message in a folder based on a subject or words within the subject etc. Both the SearchFilter and Recurrence classes with the EWS Managed API are implemented as Nested Types see for a description as to what these are. To use one of these objects within a NestedType you need to use the following format when initializing it namespace.enclosing type+nested type see So to declare a IsEqualTo filter use $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1) $view.SearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false) $findResults = $service.FindIte

Downloading Attachments and Exporting Email as eml files in the EWS Managed API using Powershell

A common and useful thing you may want to do in Powershell when working with Exchange Email automation is to download an attachment. When working with Exchange Web Services you first need to use a GetItem operation to work out what attachments are on a message then use a GetAttachment operation which returns a Byte Array of each attachments content. So all you need to do with this Byte array is write it out to a file using the System.IO.FileStream Class. To do this you first need a message object that you would normally get doing a GetItem operation in EWS in the managed API its just one line once you know the MessageID. Eg $msMessage = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service,$MessageID) Once you have the message object you will have a list of attachments and the attachmentID you need to make a GetAttachment operations. Again this is pretty easy to do using the Managed API which extrapolates the GetAttachment operation as the load method on an attachment objec
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.