Powershell + EWS假冒权限不足

时间:2015-10-09 14:31:19

标签: powershell exchangewebservices

我收到以下错误 -

Exception calling "Bind" with "2" argument(s): "The server to which the application is connected cannot impersonate the requested user due to insufficient permission."

使用以下代码 -

## Load Exchange web services DLL
## Download here if not present: http://go.microsoft.com/fwlink/?LinkId=255472
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
Import-Module $dllpath

## Creating Service Object
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)

## Setting up Admin Credentials with Impersonated Role Group rights
$user = "serviceAccount"
$pass = "P@55w0rd"
$service.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $user, $pass

## Set the URL of the CAS (Client Access Server)
#$service.AutodiscoverUrl($AccountWithImpersonationRights ,{$true})
$EWSurl = "https://server.domain.ca/EWS/Exchange.asmx"
$service.URL = $EWSurl

## Setting up ImperSonated User
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, "mailbox@domain.com")

#Connect to the Inbox and display basic statistics
$InboxFolder= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox, "mailbox@domain.com")
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$InboxFolder)
Write-Host 'Total Item count for Inbox:' $Inbox.TotalCount
Write-Host 'Total Items Unread:' $Inbox.UnreadCount

目前我只是想做一个简单的连接。然后打算下载附件。

1 个答案:

答案 0 :(得分:0)

错误告诉您使用的服务帐户" serviceAccount"没有权限模拟您尝试访问的用户。需要通过RBAC授予EWS模拟权限,请参阅https://msdn.microsoft.com/EN-US/library/office/dn722376(v=exchg.150).aspx

干杯 格伦