About: Using EWS and PowerShell

Exchange PowerShell cmdlets are used for Administrative work on a server and with mailboxes.  However, it provides very little access to things inside the mailbox.  Exchange PowerShell is geared to Admin work and not working with things inside of a mailbox. To work with items in a mailbox you need another mail – the type made for mailbox access.  You can use Exchange Web Services (EWS) against all versions of Exchange from 2007 to the latest. Most samples for using EWS are either ones with C# or raw EWS SOAP calls.  However, there is a lot of samples and information on using it with PowerShell because it's often used by Administrators and developers.

I've included information on using the EWS Managed API with PowerShell.  The training series is from a Microsoft MVP and should be well worth reading.  In addition, I'm including information covering scenarios we commonly see issues with customer code.

Beginning information:

Below is general information on the EWS Managed API.

EWS Managed API
The EWS Managed API is open-sourced and Microsoft publishes it on GitHub. It's best to download it and build in order to get the latest fixes.

Microsoft Exchange Web Services Managed API 2.2
This is Microsoft's download link.

Start using web services in Exchange

Develop web service clients for Exchange
This has links to the type of operations to be done.

Best Practices: EWS Managed API coding for Exchange

About: Exchange Web Services (EWS) – Getting started with EWS

Accessing many mailboxes:

To access more than one mailbox you will either need to use EWS Impersonation or Delegate access.  Normally EWS Impersonation is used to access many mailboxes.  However, Delegate access can also be used.  EWS Impersonation has a lot of advantages over delegate access and is far less likely to get throttled.

Authentication and EWS in Exchange

Impersonation and EWS in Exchange
With Impersonation a service account has full access to a defined set of mailboxes. What it can access in those mailboxes (such as specific folders) cannot be filtered or defined.  Only an Exchange Admin can configure an EWS Impersonation account for impersonating and configure its mailboxes to allow the impersonation.

Delegate access and EWS in Exchange
Delegate access allows a user to access certain folders in another user's mailbox  Delegate permissions can be set by a mailbox owner or administrator using an app or other app code.

Training series on EWS and PowerShell:

Below is a training series by Glen Scales.

EWS Managed API and Powershell How-To series Part 1

EWS Managed API and Powershell How-To series Part 2 - Folders

EWS Managed API and Powershell How-To series Part 3 - Items                                                                                           

EWS Managed API and Powershell How-To series Part 4 - Items Part 2

EWS Managed API and Powershell How-To Series Part 5 Delegate Operations

EWS Managed API and Powershell How-To Series Part 6 FreeBusy and OOF Operations

EWS Managed API and Powershell How-To Series Part 7 Using the Configuration Information Operation

EWS Managed API and Powershell How-To Series Part 8 Folder Permissions

EWS Managed API and Powershell How-To Series Part 9 EWS Notifications

EWS Managed API and Powershell How-To Series Part 10 Message Classifications  

EWS Managed API and Powershell How-To Series Part 11 Moderation

Note that the blog site for the above articles lot of samples where PowerShell and EWS are used. Many of these samples are very helpful for admins.

Note about headers:

There are headers which should be set and in many cases they must be set on an EWS call. Be sure to implement them in your code.

Best Practices: Important and critical headers for EWS

EWS Schema version:

The EWS Schema Version is often a point of confusion – this article discusses how it should be set:

EWS Schema Versions – Why can't I pick versions for 2007 SP2/SP3 or 2010 SP3?

Read about throttling:

It's important that you consider possible Exchange Throttling when designing your application and writing code.

Exchange throttling is your friend… well, more like a police officer.

Best Practices – EWS Throttling

EWS ServerBusyException – The server is too busy – for you

You are doing too much at one time: EWSMaxConcurrency – "too many concurrent connections opened"


Here are some additional articles to go over:

Best Practices: EWS Managed API coding for Exchange

EWS Best Practices

Best Practices – EWS Authentication and Access Issues
This article covers many of the gotcha's which you may encounter with EWS.

Exchange samples: learn through code
There are a lot of samples at this site.

Exchange 2013 101 Code Sample
It's a zip file filled with samples for a lot of EWS calls.