Home All Groups Group Topic Archive Search About

Pulling user data from Active Directory

Author
14 Apr 2006 8:04 AM
Joe Spears
Hi
Does anyone have any sample code on Pulling user data from Active
Directory??

Thanks

Author
14 Apr 2006 10:22 AM
Kevin Spencer
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

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

If the truth hurts, wear it.


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
>
Author
17 Apr 2006 6:36 PM
Raghu
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
>

AddThis Social Bookmark Button