Last post Oct 19, 2017 06:37 PM by peg.duffy
Oct 17, 2017 05:53 PM|peg.duffy|LINK
Here is a sanitized version of the code I am trying to get working
The call in Main is to
DirectoryEntry myLdapConnection = createDirectoryEntry();
static DirectoryEntry createDirectoryEntry()
// create and return new LDAP connection with desired settings
String myADSPath = "LDAPS://server.bozo.clown.com:636/OU=365Users,DC=bozo,DC=clown,DC=com";
DirectoryEntry ldapConnection = new DirectoryEntry(myADSPath, @"firstname.lastname@example.org", @"whatever12_Password", AuthenticationTypes.Secure);
When I try to make the call for DirectoryEntry de =new DirectoryEntry(adsPath,username,
password,AuthenticationTypes.Secure) it returns a DirectoryEntry object, ldapConnection,
but many of the attributes in debugger for the value, ldapConnection, returned, show this type of thing:
'ldapConnection.AdsObject' threw an exception of type
'ldapConnection.ContainerObject' threw an exception of
type'ldapConnection.Guid' threw an exception of type
'ldapConnection.IsContainer' threw an exception of type
Same for Name, NativeObject, NativeGuid,Object Security....
Examining this object using VS2010....
Do anyone have any relevant references or advice on this problem and how to resolve it? (code snippets most welcome)
Oct 17, 2017 06:18 PM|PatriceSc|LINK
And your final goal is ? If querying AD for users you also have the "new"
https://msdn.microsoft.com/en-us/library/bb384379(v=vs.100).aspx namespace which is easier to use.
Or you want to query a non AD directory using LDAP ?
Oct 17, 2017 06:26 PM|peg.duffy|LINK
My eventual goal is to create a .csv file with all users in our O365 Active Directory who have mailboxes enabled. With that list of users, I need to get their proxyaddress, primary SMTP address and other attributes. I know I can do these things with powershell,
but occasionally, once per week, the powershell program that does a similar thing, times out...never comes back. The program in PS runs every 30 minutes, M-F from 8-5...and it fails about once a week. I was hoping to replace powershell calls with a program
to create a flat file and read that data into a datatable.....
Oct 18, 2017 05:19 AM|Jean Sun|LINK
The following link shows how to query LADP to get the user information using C#, please take it as reference.
Oct 18, 2017 08:10 AM|PatriceSc|LINK
I didn't know you could use LDAP for Office 365. Your PS script uses which commands?
For this I would likely use rather the Microsoft Graph API :
You have a nuget package that provides a client side library.
If you want to keep the current approach what is the first exception you have when using actual code. I wouldn't try to diagnose an exception that happens when using the debugger viewer.
Oct 19, 2017 06:37 PM|peg.duffy|LINK
OK, I finally got this working. As one respondent suggested, I used the newer System.DirectoryServices.AccountManagement, instead of the older DirectoryServices methods.
I was just trying to get the PrincipalContext without errors like server could not be contacted. I know it was my arguments to the constructor and finally figured out the correct syntax. In case, anyone else is struggling with this.....[I have to use the
secure LDAP port 636 for my AD server]....below is a snippet. Substitute your values and I hope it works for you as it just worked for me.
string sDomainServer = "BOZO.CLOWN.COM:636"; // works
string sContainer = "DC=bozo,DC=clown,DC=com";
string sServiceUser = "bozo" + @"\" + "username";
string sServicePassword = @"some_crazy_password";
PrincipalContext aPC = new PrincipalContext(ContextType.Domain, sDomainServer, sContainer, ContextOptions.SimpleBind, sServiceUser, sServicePassword);
I was able to verify that the PrincipalContext was working by doing this...and getting result.
using (PrincipalContext oPC = new PrincipalContext(ContextType.Domain, sDomain, sContainer, ContextOptions.SimpleBind, sServiceUser, sServicePassword))
UserPrincipal qbeUser = UserPrincipal.FindByIdentity(oPC, IdentityType.SamAccountName, "pegduffy");
Thanks to everyone who replied. Now to get all users in this domain