2

I want to get all users from Exchange server, I don't want to get user's contacts. In fact, I want to get all AD users as Active Directory which we can't connect to.

     mExchangeService.ImpersonatedUserId = new ImpersonatedUserId
        {
            Id = "jack@aa.com",
            IdType = ConnectingIdType.SmtpAddress
        };
        var contacts = _mExchangeService.FindItems(new FolderId(WellKnownFolderName.Contacts),new ItemView(1000)); 

I can above code to get user's contact, but that's not I want, I want use a service account to get all Exchange web service users.

Jack Wang
  • 97
  • 1
  • 9

1 Answers1

3

You can sort of use EWS for retrieving your directory users using ExhangeService.ResolveName. The problem is that EWS will return no more than 100 users and there is no way to change it or to do any paging. So if you are in a larger company you can't really do it using EWS.

The code:

var nameResolutionCollection = service.ResolveName("SMTP:",
    ResolveNameSearchLocation.DirectoryOnly, true);
foreach (var c in nameResolutionCollection)
{
    Console.WriteLine(c.Mailbox.Address);
}
Console.WriteLine(nameResolutionCollection.Count()); // Maximum 100 users.
Jakob Christensen
  • 14,826
  • 2
  • 51
  • 81
  • Thanks, I know this method, but just can get 100 records, It's strange why just provide 100 records – Jack Wang Feb 12 '15 at 01:21
  • Thank you for this Jakob! Sadly, 100 where not enough for our company's ActiveDirectory. Is there another option you know of, or do I have to go through [ActiveDirectory directly](https://github.com/gheeres/node-activedirectory)? – Tholle Sep 22 '15 at 19:37
  • 1
    @Tholle: I think Active Directory is the way to go. – Jakob Christensen Sep 24 '15 at 07:38