Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Active Directory Attributes not represented by the UserPrincipal class

Tags:

What I mean is that right now I am using System.DirectoryServices.AccountManagement and if I use UserPrincipal class I only see the Name, Middle Name, etc

so in my codes it like

UserPrincipal myUser = new UserPrincipal(pc); myUser.Name = "aaaaaa"; myUser.SamAccountName = "aaaaaaa"; . . . . myUser.Save(); 

How would I see the attribute like mobile or info?

like image 470
Mondyak Avatar asked Oct 14 '10 02:10

Mondyak


1 Answers

In this case, you need to go one level deeper - back into the bowels of DirectoryEntry - by grabbing it from the user principal:

using (DirectoryEntry de = myUser.GetUnderlyingObject() as DirectoryEntry) {     if (de != null)     {         // Go for those attributes and do what you need to do...         var mobile = de.Properties["mobile"].Value as string;         var info = de.Properties["info"].Value as string;     } } 
like image 60
marc_s Avatar answered Sep 20 '22 13:09

marc_s