Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Overview of this book

Table of Contents (22 chapters)
Microsoft Exchange 2010 PowerShell Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting connected to EWS


When working with EWS, you first need to create an instance of the ExchangeService class that can be used to send SOAP messages to an Exchange server. This class has several properties and methods that can be used to specify explicit credentials, set the web service's end-point URL, or make a connection using the built-in AutoDiscover client. In this recipe, you'll learn how to make a connection to EWS that can be used to run custom scripts against the web service.

How to do it...

  1. The first thing we need to do is load the EWS Managed API assembly into the shell:

    Add-Type -Path C:\EWS\Microsoft.Exchange.WebServices.dll
  2. Now we can create an instance of the ExchangeService class:

    $svc = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
  3. At this point, we can use the AutoDiscoverUrl method to determine the EWS end-point on the closest Client Access Server for the mailbox with a particular SMTP address:

    $svc.AutoDiscoverUrl("[email protected]")

Now that...