Search code examples
soapexchange-serverexchangewebservices

How to get all users from Exchange with EWS


I would like to get all users from xchange server with EWS. I have figured out how to get all rooms and all appointments. But I specifically need all users thus I can CRUD users from my application. Is this even possible? I did not find any example online. Please advise on how to achieve this.

How would soap request look for user CRUD operations?


Solution

  • On Exchange 2013 and above you can use the FindPeople operation with the GUID of the address list you want to access (eg for the Global Address List you use the GAL's guid).

        <?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <soap:Header>
            <RequestServerVersion Version="Exchange2013_SP1" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
          </soap:Header>
          <soap:Body>
            <FindPeople xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
              <IndexedPageItemView MaxEntriesReturned="100" Offset="0" BasePoint="Beginning" />
              <ParentFolderId>
                <AddressListId Id="5c90c254-2463-4256-bf52-60d82e6baa44" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
              </ParentFolderId>
            </FindPeople>
          </soap:Body>
        </soap:Envelope>
    

    You can then page the results back using the Offset

    The one catch with this is you can't get the GUID you need using EWS you need to use the Get-GlobalAddressList cmdlet https://technet.microsoft.com/en-us/library/aa996579(v=exchg.160).aspx in Exchange Management Shell which will return the GUID you need for the request.

    Cheers Glen