使用EWS Managed API 2.2获取用户帐户的别名列表

时间:2017-09-05 22:14:00

标签: web-services powershell exchangewebservices ews-managed-api

在使用EWS managed API时,我很难理解如何在PowerShell中获得一些基本属性,他们的文档几乎没有使用Powershell来完成大多数任务。

我真正想看到的是用户帐户中的所有别名。但我也不了解如何在其中列出某些特定字段,例如Microsoft.Exchange.WebServices.Data.AlternateId

$Email = 'user@example.com'
$Pass = 'example4321'
#path for the Exchange WebServices DLL
$EWSPath = "C:\path\Microsoft.Exchange.WebServices.dll" 
#Connecting with EWS/Exchange
[Reflection.Assembly]::LoadFile($EWSPath) | Out-Null
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
$service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials($Email,$Pass)
$service.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx");
$service.traceenabled = "true"

#Defining the Root folder

$RootFolderId = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$email)
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service,$RootFolderId)
# ################
# Here I want to list all the user's aliases.
##################
$Mailbox = $RootFolder.getMailbox()

1 个答案:

答案 0 :(得分:1)

ResolveName https://msdn.microsoft.com/en-us/library/office/dn645423(v=exchg.150).aspx可能是最接近您将在EWS中执行此操作的内容,例如,如果您解析了该名称,然后从目录中返回联系人信息。但是它只会返回emailaddresses collection.eg

中的前3个地址
$ncCol = $service.ResolveName("address@domain.com", [Microsoft.Exchange.WebServices.Data.ResolveNameSearchLocation]::DirectoryOnly, $true);
if($ncCol.Count -gt 0){
  #Write-output ("Found " + $ncCol[0].Contact)
}

如果您使用的是Office365,那么此类型的内容最适合使用Graph API,它会返回您查找的所有信息,例如https://graph.windows.net/youorg.com/me/proxyAddresses将返回帐户的所有代理地址