PoshCode Archive  Artifact [2ed391139e]

Artifact 2ed391139e82ed7cf5c83c28aa6b27332d23a182f8e2caffeafe065b43f0421a:

  • File Get-EwsEmail.ps1 — part of check-in [98ff8057c5] at 2018-06-10 13:18:03 on branch trunk — 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 (user: halr9000 size: 1167)

# encoding: ascii
# api: powershell
# title: Get-EwsEmail
# 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: 2978
# x-archived: 2016-06-04T02:28:53
# x-published: 2012-09-28T20:30: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 }