Installing Exchange Web Services

EWS can be downloaded from the Microsoft website (https://www.microsoft.com/en-us/download/details.aspx?id=42951); the project is open source and is available on GitHub (https://github.com/OfficeDev/ews-managed-api). The installation is straightforward and will copy the files to Program FilesMicrosoftExchangeWeb Services by default.

The Exchange 2013 101 Code Samples project is a comprehensive set of examples that will get you up-to-speed with the EWS API (https://code.msdn.microsoft.com/exchange/Exchange-2013-101-Code-3c38582c).

The API is a .NET DLL; we will load it and use it in PowerShell through Import-Module, as we have done earlier. In the following example, we use the API to establish a connection with Exchange Online through the ExchangeService object and use the ImpersonatedUserId property to execute commands as test2:

Import-Module -Name "path to dllMicrosoft.Exchange.WebServices.dll"

$exchWS = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService

$exchWS.Credentials = $creds.GetNetworkCredential();
$exchWS.AutodiscoverUrl('[email protected]', {$true})

$exchWS.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId( [Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, "[email protected]")

$rule = New-Object Microsoft.Exchange.WebServices.Data.Rule

$mobilePhone = New-Object Microsoft.Exchange.WebServices.Data.MobilePhone("test2","+3015555555")
$rule.Actions.SendSMSAlertToRecipients.Add($mobilePhone)

$rule.DisplayName = "SMS Alert 2"

$rule.Conditions.FromAddresses.Add("[email protected]")

$createRequest = New-Object Microsoft.Exchange.WebServices.Data.CreateRuleOperation($rule)
$operations = New-Object Microsoft.Exchange.WebServices.Data.RuleOperation[] 1
$operations[0] = $createRequest

$exchWS.UpdateInboxRules($operations, $false)

Impersonating a user will work only if the account used to run the scripts is set up with access to do the operation. In the next section, we will do this as we introduce security and role-based access.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.44.182