Skip to main content

Posts

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 http://msdn.microsoft.com/en-us/library/ms229027.aspx 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 http://weblogs.asp.net/soever/archive/2006/12/11/powershell-and-using-net-enum-types.aspx 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...

Mail Enabling a Public folder with the EWS Managed API and finding and changing the primary email address without using Exchange cmdlets

If your working with Public Folders in the EWS Managed API then you may want to mailenable a new or existing Public Folder without using EMS cmdlets. I described a method that you can use to mail enable Public folders using EWS a while ago here and this same method will work with a little bit of different code. Like the previous post you need to set the following 2 properties to mail enabled a folder. PR_PUBLISH_IN_ADDRESS_BOOK = 0x3FE6000B PR_PF_PROXY_REQUIRED = 0x671F000B So if you want to mailenable an existing folder that you have the path for say its "firstlevel/secondlevel/newfolder" you will first need to have some code that will find the folder based on the path by doing a search. Then once you have the folder ID you can Bind to the folder and set those Mapi properties. Using a UpdateFolder operation was one of the harder operations in normal EWS proxy code but its now so much easier to do in the EWS Managed API. Once you have set these properties a backgroup process ...

Acknowledging Appointment reminders with WebDAV

One thing that can be little tricky if your working in WebDAV is dealing with appointment reminders, especially when you have to deal with recurring appointments. If you dont use the right method its easy to break the recurrance of appointments. The best way of working something like this out is have a look at the way OWA does it and then just use the same xml. So basically what you end up with is firstly a method to acknowledge non-recurring appointment reminders by removing the reminderoffset property. And a method to acknowledge recurring appointment reminders by setting the remindernexttime property. I've put a download of this VBS script here the code looks like eg set req = Createobject("microsoft.xmlhttp") CalendarURL = "https://servername/exchange/mailbox/calendar" AppointmentURL = CalendarURL & "/appointment.eml" If RecurringAppointment = false Then xmlstr = "<?xml version=""1.0""?><a:propertyupdate xm...

Mailbox Size Summary reporting Gui for Exchange 2007

Picking up again on the topic i touched on in January about creating different summary reports of how size and resources are consummed within an Exchange enviroment he's a script that takes it in another direction (and dont we need one of those). A number of people have asked questions about how they can report on mailbox usage not just based on particular users but usage by particular OU or other User property eg Department,Office etc. An here's the script to do it How it works This script first combines 3 different Exchange cmdlets to build a displayable and redisplayble dataset that is stored in hashtable. The Get-User cmdlet is used to get all the user information and a number of properties such as the ExchangeGUID,MailboxSize and what OU a users is in is addded to the standard Get-User object and then the object is stored in a hashtable indexed by the Active Directory GUI. Because you can't link directly Get-User and Get-Mailboxstatistics directly without using Pipelin...

Add Delegates to a Mailbox with Powershell and the EWS Managed API

****Update if you looking for something to delete invalid delgates have a read of this http://gsexdev.blogspot.com/2011/03/dealing-with-invalid-delegates-with.html as well **** ****Update 2  for a better post on adding/removing and updating delegates see http://gsexdev.blogspot.com.au/2012/03/ews-managed-api-and-powershell-how-to.html   Someone emailed me about this one today and its one thing that can now easily be solved using the EWS Managed API. There’s already a good C# sample on MSDN for doing this http://msdn.microsoft.com/en-us/library/dd633621.aspx . To convert this to something you can use in Powershell once you have downloaded and installed the EWS Managed API would look like the following below. This example sets the calendarpermissions to editor and the inbox to read for full details of what other permissions you can set have a look at the SDK . $delegatetoAdd = "delage@youdomain.com" $dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Mi...
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.