J Joe Spears Apr 14, 2006 #1 Hi Does anyone have any sample code on Pulling user data from Active Directory?? Thanks
K Kevin Spencer Apr 14, 2006 #2 This is done using the System.DirectoryServices namespace. You can get information about the namespace here: http://msdn.microsoft.com/library/d...s/cpref/html/frlrfsystemdirectoryservices.asp Specifically, you would use the LDAP protocol with a System.DirectoryServices.DirectoryEntry instance. You can read up on this class at: http://msdn.microsoft.com/library/d...ctoryservicesdirectoryentryclassctortopic.asp The documentation for the constructor has some nice samples: http://msdn.microsoft.com/library/e...esdirectoryentryclassctortopic.asp?frame=true -- HTH, Kevin Spencer Microsoft MVP Professional Numbskull If the truth hurts, wear it.
This is done using the System.DirectoryServices namespace. You can get information about the namespace here: http://msdn.microsoft.com/library/d...s/cpref/html/frlrfsystemdirectoryservices.asp Specifically, you would use the LDAP protocol with a System.DirectoryServices.DirectoryEntry instance. You can read up on this class at: http://msdn.microsoft.com/library/d...ctoryservicesdirectoryentryclassctortopic.asp The documentation for the constructor has some nice samples: http://msdn.microsoft.com/library/e...esdirectoryentryclassctortopic.asp?frame=true -- HTH, Kevin Spencer Microsoft MVP Professional Numbskull If the truth hurts, wear it.
R Raghu Apr 17, 2006 #3 Here is a sample: using System.DirectoryServices; using System.Security.Principal; public void LearnLDAPUserQuery() { string userPath = "CN=my user,OU=Users and Computers,DC=corp"; string ldapPrefix = "LDAP://"; DirectoryEntry userEntry = new DirectoryEntry(ldapPrefix + userPath); Console.WriteLine(userEntry.Path); Console.WriteLine(userEntry.SchemaClassName); foreach (string propName in userEntry.Properties.PropertyNames) { Console.WriteLine("{0}: {1}", propName, userEntry.Properties[propName].Value); } dumpActiveDirectorySecurity(userEntry.ObjectSecurity); Console.WriteLine("logonCount: {0}", userEntry.Properties["logonCount"].Value); } private void dumpActiveDirectorySecurity(ActiveDirectorySecurity security) { NTAccount groupAccount = security.GetGroup(typeof(NTAccount)) as NTAccount; Console.WriteLine("User belongs to group: {0}", groupAccount.Value); }
Here is a sample: using System.DirectoryServices; using System.Security.Principal; public void LearnLDAPUserQuery() { string userPath = "CN=my user,OU=Users and Computers,DC=corp"; string ldapPrefix = "LDAP://"; DirectoryEntry userEntry = new DirectoryEntry(ldapPrefix + userPath); Console.WriteLine(userEntry.Path); Console.WriteLine(userEntry.SchemaClassName); foreach (string propName in userEntry.Properties.PropertyNames) { Console.WriteLine("{0}: {1}", propName, userEntry.Properties[propName].Value); } dumpActiveDirectorySecurity(userEntry.ObjectSecurity); Console.WriteLine("logonCount: {0}", userEntry.Properties["logonCount"].Value); } private void dumpActiveDirectorySecurity(ActiveDirectorySecurity security) { NTAccount groupAccount = security.GetGroup(typeof(NTAccount)) as NTAccount; Console.WriteLine("User belongs to group: {0}", groupAccount.Value); }