Get a complete list of users in Microsoft Exchange
1 answer
In 2010 with EWS, there is no operation that will return this, you will only have a ResolveName operation and an expandgroup operation. So in EWS, you can use a workaround to place all the users you want to return to a group and then use ExpandGroup on that group.
Otherwise, you have to use LDAP directly using System.DirectoryServices like http://www.infinitec.de/post/2011/10/25/Searching-the-Global-Address-List-C-Edition.aspx or use Exchange Management Shell and Get-Mailbox see http://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx
Another workaround is if you have less than 100 objects in your GAL, you can use "SMTP:" with the resolveName, for example
PropertySet cntProp = new PropertySet(BasePropertySet.FirstClassProperties);
NameResolutionCollection ncCol = service.ResolveName("SMTP:", ResolveNameSearchLocation.DirectoryOnly, true, cntProp);
foreach (NameResolution nc in ncCol) {
if(nc.Contact.Alias != null){
Console.WriteLine("Address : " + nc.Mailbox.Address);
Console.WriteLine("Alias : " + nc.Contact.Alias);
Console.WriteLine("Type : " + nc.Mailbox.MailboxType);
}
}
Cheers Glen
+4
source to share