Search code examples
web-servicespowershellexchangewebservicesews-managed-api

Using EWS Managed API 2.2 to get a list of aliases of user's account


I am having a hard time to understand how to get some basic proprieties in PowerShell when using the EWS managed API their documentation has little to nothing about using Powershell to accomplish most tasks.

What I really want to see is all the aliases in the user's account. But I also don't understand how to get some specific fields listed there e.g 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()

Solution

  • ResolveName https://msdn.microsoft.com/en-us/library/office/dn645423(v=exchg.150).aspx is probably the closest you will get to something that will do that in EWS eg if you resolve the name and then return the Contact information from the directory. However it will only return the first 3 addresses in the emailaddresses collection.eg

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

    If you are using Office365 then this type of thing is best suited to the Graph API which will return all the information your looking for eg https://graph.windows.net/youorg.com/me/proxyAddresses will return all the proxyaddresses of an account