PoshCode Archive  Artifact [15da4a7920]

Artifact 15da4a7920283ab1c0a021c2dfb574d33a61331f3a09e0417cea619fdc7445e4:

  • File rajabatak-my-opera-com.ps1 — part of check-in [bf393d68fc] at 2018-06-10 13:18:52 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: 1177)

# 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 }