Skip to main content

Setting single line view in OWA for a folder via Powershell using the EWS Managed API

Early this year i posted a script for turning the reading pain off and on in OWA 2007 using some EWS proxy code in powershell. The same thing can also be done using the EWS Managed API as well as other properties in OWA like the single line view which someone asked about this week. So here is a script that can be used for setting both of these values.

Single Line View property,

Like the reading pain this OWA setting in controlled by a property that is set on each folder

http://schemas.microsoft.com/exchange/wcmultiline

To use this in Powershell in the EWS Managed API you need to define a Extended Property using the Public Strings PropertySet eg

$wcmultiline = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::PublicStrings,"http://schemas.microsoft.com/exchange/wcmultiline", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Boolean);

1 = True mean multiline view is On (Default)
0 = False meaning singleline view is enabled

If you wanted to set the reading pain the definition looks like

$rcReadingPain = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::PublicStrings,"http://schemas.microsoft.com/exchange/preview", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String);

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


Using It

If you haven't used the EWS Managed API in powershell before take a look at this post first

I'll show an example that uses delegate access to access another users mailbox and set this property. The first thing we will do is create a variable to hold the email address of the mailbox you want to modify

$usertoSet = "user@domain.com"

Next load the EWS Managed API dll and create a service object

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

The script is going to use the current logged on user to find the CAS uri using autodiscover and connect to the mailbox of the user. If you want to specify a specific CAS or user credential see the other post i reference to show what modifications need to be made to the script.


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

$service.AutodiscoverUrl($aceuser.mail.ToString())

Next Define the Folder to connect to using EWS delegate access

$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$usertoSet)

Define the Extendedproperty

$wcmultiline = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::PublicStrings,"http://schemas.microsoft.com/exchange/wcmultiline", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Boolean);


Bind to the Folder
$Folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)

Add the Extended property setting the value to 0 which will enable single line view

$Folder.ExtendedProperties.Add($wcmultiline,"0")

Call update which will commit the changes to the Folder

$Folder.update()

Pretty Easy right ;)

If you doing a lot of users put the code in a function and then call it from within a get-mailbox loop using the email address.

If you wanted to set every Folder in the mailbox you need to loop through all folders thats pretty easy as well using a Deep Traversal so i've put a sample of that as well as a simple inbox sample in the download which you can get from here

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 https://mydom-my.sharepoint.com/personal/gscales_domain_com/Documents/Email%20attachments/filename.txt 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 ' https://mydom-my.sharepoint.com/personal/gscales_domain_com/Documents/Email%20attachments/filena

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  https://en.wikipedia.org/wiki/Opportunistic_TLS .  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.