|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Pulling user data from Active DirectoryHi
Does anyone have any sample code on Pulling user data from Active Directory?? Thanks This is done using the System.DirectoryServices namespace. You can get
information about the namespace here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/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/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryservicesdirectoryentryclassctortopic.asp The documentation for the constructor has some nice samples: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemdirectoryservicesdirectoryentryclassctortopic.asp?frame=true -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull If the truth hurts, wear it. "Joe Spears" <joespe***@hotmail.co.uk> wrote in message news:WHI%f.52205$8Q3.14978@fe1.news.blueyonder.co.uk... > Hi > Does anyone have any sample code on Pulling user data from Active > Directory?? > > Thanks > 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); } Show quote "Joe Spears" <joespe***@hotmail.co.uk> wrote in message news:WHI%f.52205$8Q3.14978@fe1.news.blueyonder.co.uk... > Hi > Does anyone have any sample code on Pulling user data from Active > Directory?? > > Thanks > |
|||||||||||||||||||||||