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

Exporting attachments from a mailbox


The Exchange Management Shell provides cmdlets that allow you to export e-mail messages from one mailbox to another mailbox. These e-mails can then be exported to a PST file, or you can open an alternate mailbox and access the data. The only limitation is that this provides no option to export only the message attachments. The EWS Managed API has this functionality built in. In this recipe, you'll learn how to export e-mail attachments from an Exchange mailbox using PowerShell.

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. Next, create a property set...