Skip to main content

Changing OWA configuration setting with EWS in Exchange 2010

The ability to change and customise the default configuration of OWA is an often sort out and in previous versions of Exchange hard to achieve task. Especially for those with Large Exchange Orgs and standardised training or custom security requirements where the default settings come into conflict with other policies. Underlying a lot of OWA configuration settings are stored in FAI items (folder associated items) in a users mailbox using the Configuration Information Protocol Specification documented in

Along with the ability to access FAI items which was previously not possible in Exchange 2007 using EWS, Exchange 2010 also introduces a new UserConfiguration Operation in EWS that provides some Typed objects the makes dealing with configuration objects a lot easier and safer for those that wish to do so. (I still wouldn't guarantee the support response you would get if you do use these Operations and stuff your Exchange Org completely this is a risk you should understand before undertaking such an endeavor). What having these strong objects to use if your using Proxy code or the EWS Managed API means is that a task that may have taken a lot effort and reverse engineering in the past to achieve is really now something you can do fairly easy with a couple of lines of code or script.

The User configuration FAI items can be located in different folders in a Mailbox the one im going to focus on in this post is the OWA.UserOptions object which contain things such as the readingpane setting, OWA signiture and other general settings. The message itself has a message class of IPM.Configuration.OWA.UserOptions if you looked at it with a Mapi editor and its located in the Non_IPM_Subtree (ed Note since the removal of Dav in Exchange 2010 is this still the right terminology??).

This brings up an important point for anybody trying to modify these type of objects one tool you will find invaluable is a Mapi editory like the MFCMapi or OutlookSpy. Another useful tool is now the EWS editor these two tools will make doing this type of thing a lot eaiser as they can allow you to browse and see the current values of properties on items. You should also read the the protocol document i linked above and have an understanding of the datatypes involved with the properties your setting and make sure you adhere to this. Eg dont use a String where a Interger is expected etc.

For this post im also using the EWS Managed API which saves time and sanity when writing EWS code.

Lets get down to the code the first thing you need to do is get the FolderID for the Non_Ipm_Subtee, to do this you Bind to the Root folder and use the parentFolderID property

Folder Root = Folder.Bind(service, WellKnownFolderName.Root);

Next you use the UserConfiguration objects bind method and pass the following parameters in

UserConfiguration OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions", Root.ParentFolderId, UserConfigurationProperties.All);

Note that you take the MessageClass of the Item IPM.Configuration.OWA.UserOptions and drop the IPM.Configuration part.

This will then get the existing configuration object settings from this particular folder item which for this item will be returned as a dictionary collection. If you want to enum through all the properties you can do the following

IDictionaryEnumerator ConfigEnum = (IDictionaryEnumerator)OWAConfig.Dictionary.GetEnumerator();
while (ConfigEnum.MoveNext()) {
Console.WriteLine("Key : " + ConfigEnum.Key);
Console.WriteLine("Value : " + ConfigEnum.Value);

To Set a value it pretty simple eg

OWAConfig.Dictionary["previewmarkasread"] = 2;
OWAConfig.Dictionary.Add("previewmarkasread", 2);

This turns the Mark as Read off in the previewpane in OWA note that this is a Intager value.

To do this in Powershell script that you could feed with get-mailbox it would look like the following I've put a download of the code here

$MailboxName = ""

$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)

$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
$aceuser = [ADSI]$sidbind


$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$Root = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$OWAConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($service, "OWA.UserOptions", $Root.ParentFolderId, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
$OWAConfig.Dictionary["previewmarkasread"] = 2 }
$OWAConfig.Dictionary.Add("previewmarkasread", 2)

Popular posts from this blog

Downloading a shared file from Onedrive for business using Powershell

I thought I'd quickly share this script I came up with to download a file that was shared using One Drive for Business (which is SharePoint under the covers) with Powershell. The following script takes a OneDrive for business URL which would look like This script is pretty simple it uses the SharePoint CSOM (Client side object Model) which it loads in the first line. It uses the URI object to separate the host and relative URL which the CSOM requires and also the SharePointOnlineCredentials object to handle the Office365 SharePoint online authentication. The following script is a function that take the OneDrive URL, Credentials for Office365 and path you want to download the file to and downloads the file. eg to run the script you would use something like ./spdownload.ps1 '

Export calendar Items to a CSV file using EWS and Powershell

Somebody asked about this last week and while I have a lot of EWS scripts that do access the Calendar I didn't have a simple example that just exported a list of the Calendar events with relevant information to a CSV file so here it is. I've talked on this one before in this howto  but when you query the calendar folder using EWS you need to use a CalendarView which will expand any recurring appointments in a calendar. There are some limits when you use a calendarview in that you can only return a maximum of 2 years of appointments at a time and paging will limit the max number of items to 1000 per call. So if you have a calendar with a very large number of appointments you need to break your query into small date time blocks. In this example script I'm just grabbing the next 7 days of appointments if you want to query a longer period you need to adjust the following lines (keeping in mind what I just mentioned) #Define Date to Query $StartDate = (Get-Date) $EndDate

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why I wrote th
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.