<# Untested sample code, use at your own risk! #> ## Setup the Exchange Service Binding $uri = "https://exchangeserver/ews/exchange.asmx" $exchangeservicebinding = new-webserviceproxy -NameSpace "EWS" -URI $uri -UseDefaultCredential -Class EWS $exchangeservicebinding.RequestServerVersionValue = new-object EWS.RequestServerVersion $exchangeservicebinding.RequestServerVersionValue.Version = [EWS.ExchangeVersionType]::Exchange2007_SP1 $exchangeservicebinding.Url = $uri ## Create and Populate the Parent Folder ID Collection [EWS.DistinguishedFolderIdType]$parentfolderid = new-object EWS.DistinguishedFolderIdType $parentfolderid.Id = [EWS.DistinguishedFolderIdNameType]::inbox [EWS.BaseFolderIdType[]]$parentfolderids = $parentfolderid ## Create an ItemShape and set it to return All Properties [EWS.ItemResponseShapeType]$itemshape = new-object EWS.ItemResponseShapeType $itemshape.BaseShape = [EWS.DefaultShapeNamesType]::AllProperties ## Create the FindItemType object and populate with the Parent Folder Ids and Item Shape [EWS.FindItemType]$finditemtype = new-object EWS.FindItemType $finditemtype.ParentFolderIds = $parentfolderids $finditemtype.ItemShape = $itemshape ## Make the call to the webservice [EWS.FindItemResponseType]$finditemresponses = $exchangeservicebinding.FindItem($finditemtype) ## Loop through the returned messages and print some basic info [EWS.MessageType]$messagetype foreach($messagetype in $finditemresponses.ResponseMessages.Items[0].RootFolder.Item.Items) { Write-Host "From: " $messagetype.From.Item.Name Write-Host "Subject: " $messagetype.Subject Write-Host "Received: " $messagetype.DateTimeReceived.Date Write-Host "-------------------------------------------------------" Write-Host "ItemId: " $messagetype.ItemId.Id Write-Host "=======================================================" Write-Host } <# download code here #>