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

Searching mailboxes


The EWS Managed API can be used to search one or more folders within an Exchange mailbox. The latest version of the API supports searches using Advanced Query Syntax, allowing us to search folders using the indexes created by the Exchange Search service. This makes searching a mailbox folder very fast and less resource intensive than methods that were used with previous versions of the API. In this recipe, you'll learn how to search the contents of a mailbox through PowerShell and the EWS Managed API.

How to do it...

  1. First, load the assembly, create the ExchangeService object and connect to EWS:

    Add-Type -Path C:\EWS\Microsoft.Exchange.WebServices.dll
    $svc = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
    $svc.AutoDiscoverUrl("[email protected]")
  2. Next, create a view for the total number of items that should be returned from the search:

    $view = New-Object -TypeName `
    Microsoft.Exchange.WebServices.Data.ItemView `
    -ArgumentList 100
  3. The next step is to...