Solved

Get the AD department field

Posted on 2011-02-22
2
1,352 Views
Last Modified: 2012-05-11
I can successfully pull out fields from an AD account but unable to get the 'department' field using System.DirectoryServices.AccountManagement for framework 3.5.

The object 'user' that's returned by UserPrincipal does not seem to have a property for this or one that I cannot find. Anyone have a solution instead of using the old System.DirectoryServices model?
using System.DirectoryServices.AccountManagement;

PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, "MyDomain", "DC=MyDomain,DC=com,DC=au");

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.SamAccountName, "aduser");

 lblInfo.Text = "<br>" + user.DisplayName.ToString();
 lblInfo.Text += "<br>" + user.EmailAddress.ToString();

Open in new window

0
Comment
Question by:chris_desborough
2 Comments
 
LVL 12

Accepted Solution

by:
geowrian earned 250 total points
ID: 34957459
0
 
LVL 1

Author Closing Comment

by:chris_desborough
ID: 34957701
Thanks geowrian - works great. Thanks for the tip.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now