Saturday, January 24, 2009

Turning the Reading / Preview pane on and off in OWA in Exchange 2007 with EWS and Powershell

The Reading pane (or preview pane) is one the features of the premium version of Outlook Web Access on 2007. Due to Security or bandwidth (or other) worries you may want to turn this off on particular folders for your users (although they will still be able to still turn this back on using OWA). There is no global way of turnin it off so you need to modify the property that controls this on each folder you want to be affected.

The property that controls the Preview pane is this doesn't get set by default so in the absence of this property the preview pane is on. If the property does exist it will be one of three values

0 - Preview Pane is off
1 - Preview Pane set to rights
2 - Preview Pane set to bottom

To set this property you can use any of the Exchange API's on 2007 the best API to use is EWS in C# if you wanted to set this property you would need to use the following property definition in a FolderUpdate Operation

PathToExtendedFieldType ppainprop = new PathToExtendedFieldType();
ppainprop.PropertyName = "";
ppainprop.PropertyType = MapiPropertyTypeType.String;
ppainprop.DistinguishedPropertySetIdSpecified = true;
ppainprop.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;

I've put together some methods in my EWS Powershell library to allow some easy PSH code to query and update this value on mailbox folders. I've created two seperate versions of a sample script to do this the first just sets this property on the inbox folder while the second loops through every mailbox folder and sets this property on every folder in a mailbox.

To use this script you need my ewsutil library which contains the EWS code you can download this from more information on using the library and connection and authentication options this is documented in another post.

I've posted both versions of the script here the version that loops through all folders looks like

$setPPTo = "0"

$casUrl = "https://servername/ews/exchange.asmx"
$mbMailboxEmail= ""
$ewc = new-object EWSUtil.EWSConnection("",$false, "username", "Password", "domain",$casUrl)

$fldarry = new-object EWSUtil.EWS.BaseFolderIdType[] 1
$dTypeFld = new-object EWSUtil.EWS.DistinguishedFolderIdType
$dTypeFld.Id = [EWSUtil.EWS.DistinguishedFolderIdNameType]::msgfolderroot
$mbMailbox = new-object EWSUtil.EWS.EmailAddressType
$mbMailbox.EmailAddress = $mbMailboxEmail
$dTypeFld.Mailbox = $mbMailbox
$fldarry[0] = $dTypeFld

$FolderList = $ewc.GetAllMailboxFolders($fldarry)
$fldarry1 = new-object EWSUtil.EWS.BaseFolderIdType[] $FolderList.Count
for ($fcint=0;$fcint -lt $FolderList.Count;$fcint++){
$fldarry1[$fcint] = $FolderList[$fcint].FolderId
$psPreviewSetting = new-object EWSUtil.EWS.PathToExtendedFieldType
$psPreviewSetting.DistinguishedPropertySetIdSpecified = $true
$psPreviewSetting.DistinguishedPropertySetId = [EWSUtil.EWS.DistinguishedPropertySetType]::PublicStrings
$psPreviewSetting.PropertyName = ""
$psPreviewSetting.PropertyType = [EWSUtil.EWS.MapiPropertyTypeType]::Integer
$beparray = new-object EWSUtil.EWS.BasePathToElementType[] 1
$beparray[0] = $psPreviewSetting
$Folders = $ewc.GetFolder($fldarry1,$beparray)
If ($Folders.Count -ne 0) {
ForEach ($Folder in $Folders) {
$cval = "n/a"
if ($Folder.extendedProperty -ne $null){
$cval = $Folder.extendedProperty[0].Item.ToString()
switch ($Folder.extendedProperty[0].Item.ToString()){
0 { $Folder.DisplayName + " Preview Pane Set Off"}
1 { $Folder.DisplayName + " Preview Pane Set Right"}
2 { $Folder.DisplayName + " Preview Pane Set Bottom"}
$Folder.DisplayName + " Not set will default to On"
if ($cval -ne $setPPTo){
$exProp = new-object EWSUtil.EWS.ExtendedPropertyType
$exProp.ExtendedFieldURI = $psPreviewSetting
$exProp.Item = $setPPTo