Solved

Get the AD department field

Posted on 2011-02-22
2
1,394 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 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