Turning off the Reading / Preview Pane on all folders in OWA in Exchange 2013 and Exchange Online in EWS with Powershell
Exchange 2013 and Exchange Online has a cool new feature in OWA to let you control the Reading pane setting on all folders in your Mailbox in OWA eg. (in previous versions you had to manage it yourself per folder).
When you set this setting in OWA and check the "Apply to all folders" box, in your mailbox it sets a configuration setting called GlobalReadingPanePosition in the OWA.UserOptions FAI (Folder Associated Item) in the Non_IPM Root of your Mailbox. The following values control the position of the Reading Pane on all folders
0 - Hides the Reading Pane
1 - Shows the Reading Pane on the Rights (this is the default)
2 - Shows the Reading Pane at the bottom
To Access this FAI Item in EWS you use the UserConfiguration class which makes accessing the Roaming Dictionary structure where this particular value is held really easy. Eg the following script will turn the Reading pane off on all Folders in the mailbox its ran against. I've put a download of this script here the code itself looks like
When you set this setting in OWA and check the "Apply to all folders" box, in your mailbox it sets a configuration setting called GlobalReadingPanePosition in the OWA.UserOptions FAI (Folder Associated Item) in the Non_IPM Root of your Mailbox. The following values control the position of the Reading Pane on all folders
0 - Hides the Reading Pane
1 - Shows the Reading Pane on the Rights (this is the default)
2 - Shows the Reading Pane at the bottom
To Access this FAI Item in EWS you use the UserConfiguration class which makes accessing the Roaming Dictionary structure where this particular value is held really easy. Eg the following script will turn the Reading pane off on all Folders in the mailbox its ran against. I've put a download of this script here the code itself looks like
- ## Get the Mailbox to Access from the 1st commandline argument
- $MailboxName = $args[0]
- ## Load Managed API dll
- Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
- ## Set Exchange Version
- $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
- ## Create Exchange Service Object
- $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
- ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials
- #Credentials Option 1 using UPN for the windows Account
- $psCred = Get-Credential
- $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
- $service.Credentials = $creds
- #Credentials Option 2
- #service.UseDefaultCredentials = $true
- ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates
- ## Code From http://poshcode.org/624
- ## Create a compilation environment
- $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
- $Compiler=$Provider.CreateCompiler()
- $Params=New-Object System.CodeDom.Compiler.CompilerParameters
- $Params.GenerateExecutable=$False
- $Params.GenerateInMemory=$True
- $Params.IncludeDebugInformation=$False
- $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
- $TASource=@'
- namespace Local.ToolkitExtensions.Net.CertificatePolicy{
- public class TrustAll : System.Net.ICertificatePolicy {
- public TrustAll() {
- }
- public bool CheckValidationResult(System.Net.ServicePoint sp,
- System.Security.Cryptography.X509Certificates.X509Certificate cert,
- System.Net.WebRequest req, int problem) {
- return true;
- }
- }
- }
- '@
- $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
- $TAAssembly=$TAResults.CompiledAssembly
- ## We now create an instance of the TrustAll and attach it to the ServicePointManager
- $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
- [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
- ## end code from http://poshcode.org/624
- ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use
- #CAS URL Option 1 Autodiscover
- $service.AutodiscoverUrl($MailboxName,{$true})
- "Using CAS Server : " + $Service.url
- #CAS URL Option 2 Hardcoded
- #$uri=[system.URI] "https://casservername/ews/exchange.asmx"
- #$service.Url = $uri
- ## Optional section for Exchange Impersonation
- #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
- $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
- #Specify the Root folder where the FAI Item is
- $UsrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($service, "OWA.UserOptions", $folderid, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
- if($UsrConfig.Dictionary.ContainsKey("GlobalReadingPanePosition")){
- $UsrConfig.Dictionary["GlobalReadingPanePosition"] = 0
- }
- else{
- $UsrConfig.Dictionary.Add("GlobalReadingPanePosition",0)
- }
- $UsrConfig.Update()
- "Item updated"