by

Configure the default calendar view in OWA in Alternate 2013 and Alternate On-line utilizing EWS and Powershell

Configure the default calendar view in OWA in Alternate 2013 and Alternate On-line utilizing EWS and Powershell If you’re after the next stage of management over the default setting in OWA, EWS presents you the flexibility to configure most of the default setting by modifying the FAI (folder related Merchandise) configuration merchandise that controls that setting. One instance of a setting you could modify is the default view of the calendar in OWA  eg  the next setting

When are person makes a change to this setting in OWA, the setting is saved in an FAI merchandise with an Merchandise Class of OWA.ViewStateConfiguration in a roaming dictionary property known as CalendarViewTypeDesktop.

The values for every of the setting are

1 = Day
2 = Week
3 = Work week
4 = Month

The next script first checks to see if the OWA.ViewStateConfiguration config merchandise exists (on a brand new mailbox if the person has by no means logged into OWA it most likely wont exist).

To make use of this script you run it with the identify of the Mailbox you need to run it in opposition to and the worth for the enum you need to use eg to set the default as Work week use

./SetOWACalendarView.ps1 mailbox@area.com 3

I’ve put a download of this script right here

The code itself appears like

  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
## Get the Mailbox to Entry from the first commandline argument
$MailboxName = $args[0]

$CalendarSetting = $args[1]

## Load Managed API dll
###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT
$EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path 'Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Providers'|Type-Object Identify -Descending| Choose-Object -First 1 -ExpandProperty Identify)).'Set up Listing') + "Microsoft.Exchange.WebServices.dll")
if (Take a look at-Path $EWSDLL)
{
Import-Module $EWSDLL
}
else
{
"$(get-date -format yyyyMMddHHmmss):"
"This script requires the EWS Managed API 1.2 or later."
"Please download and install the current version of the EWS Managed API from"
"http://go.microsoft.com/fwlink/?LinkId=255472"
""
"Exiting Script."
exit
}

## Set Alternate Model
$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Alternate2013

## Create Alternate Service Object
$service = New-Object Microsoft.Alternate.WebServices.Knowledge.ExchangeService($ExchangeVersion)

## Set Credentials to make use of two choices are availible Option1 to make use of explict credentials or Choice 2 use the Default (logged On) credentials

#Credentials Choice 1 utilizing UPN for the home windows Account
$psCred = Get-Credential
$creds = New-Object System.Internet.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
$service.Credentials = $creds
#$service.TraceEnabled = $true
#Credentials Choice 2
#service.UseDefaultCredentials = $true

## Select to disregard any SSL Warning points attributable to Self Signed Certificates

## Code From http://poshcode.org/624
## Create a compilation surroundings
$Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler=$Supplier.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 Native.ToolkitExtensions.Internet.CertificatePolicy{
public class TrustAll : System.Internet.ICertificatePolicy {
public TrustAll() {
}
public bool CheckValidationResult(System.Internet.ServicePoint sp,
System.Safety.Cryptography.X509Certificates.X509Certificates cert,
System.Internet.WebRequest req, int downside) {
return true;
}
}
}
'@
$TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly

## We now create an occasion of the TrustAll and fasten it to the ServicePointManager
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll

## finish code from http://poshcode.org/624

## Set the URL of the CAS (Consumer Entry Server) to make use of two choices are availbe to make use of Autodiscover to search out the CAS URL or Hardcode the CAS to make use of

#CAS URL Choice 1 Autodiscover
$service.AutodiscoverUrl($MailboxName,{$true})
"Using CAS Server : " + $Service.url

#CAS URL Choice 2 Hardcoded

#$uri=[system.URI] "https://casservername/ews/exchange.asmx"
#$service.Url = $uri

## Elective part for Alternate Impersonation

#$service.ImpersonatedUserId = new-object Microsoft.Alternate.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)

#Test for current Merchandise
$folderid= new-object Microsoft.Alternate.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$SfSearchFilter = new-object Microsoft.Alternate.WebServices.Knowledge.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass,"IPM.Configuration.OWA.ViewStateConfiguration")
$ivItemView = New-Object Microsoft.Alternate.WebServices.Knowledge.ItemView(1)
$ivItemView.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Related
$fiResults = $service.FindItems($folderid,$SfSearchFilter,$ivItemView)
if($fiResults.Objects.Rely -eq 0){
Write-Host ("No Config Item found, create new Item")
$UMConfig = New-Object Microsoft.Alternate.WebServices.Knowledge.UserConfiguration -ArgumentList $service
$UMConfig.Save("OWA.ViewStateConfiguration",$folderid)
}
else{
Write-Host ("Existing Config Item Found");
}
#Specify the Root folder the place the FAI Merchandise is
$UsrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($service, "OWA.ViewStateConfiguration", $folderid, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
if($UsrConfig.Dictionary.ContainsKey("CalendarViewTypeDesktop")){
$UsrConfig.Dictionary["CalendarViewTypeDesktop"] = $CalendarSetting
}
else{
$UsrConfig.Dictionary.Add("CalendarViewTypeDesktop",$CalendarSetting)
}
$UsrConfig.Replace()
"Mailbox Updated"