# encoding: ascii # api: powershell # title: rajabatak@my.opera.com # description: This is a sample script to read emails from an Inbox using Exchange Web Services. The code is a basic port of the C# found here: http://omegacoder.com/?p=454. The EWS SDK is a dependency: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c3342fb3-fbcc-4127-becf-872c746840e1 # version: 1.1 # author: halr9000 # license: CC0 # x-poshcode-id: 3017 # x-archived: 2016-03-17T13:39:54 # x-published: 2012-10-21T09:43:00 # # $ewsPath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll" Add-Type -Path $ewsPath $ews = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList "Exchange2007_SP1" $cred = (Get-Credential).GetNetworkCredential() $ews.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $cred.UserName, $cred.Password, $cred.Domain $ews.AutodiscoverUrl( ( Read-Host "Enter mailbox (email address)" ) ) $results = $ews.FindItems( "Inbox", ( New-Object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 10 ) ) $results.Items | ForEach-Object { $_.Subject }