Update full name in Active Directory

I was plunged into the deep end using Active Directory (I am a web developer, go fig). I have a user who changed the first / last name, but the full name has not changed, which causes problems with sharing the BCM database. How to update it to update the full name.

I don’t know how AD works, but for some reason higher takeoffs decided my job.

Any help would be really appreciated.

+3
source share
1 answer

Are you on .NET 3.5? If so, check out this MSDN article: Managing Directory Security Principles in the .NET Framework 3.5 .

CodeProject: Howto: () Active Directory #

System.DirectoryServices MSDN.

Active Directory # VB.NET, :

.NET

alt text

" " ( : DisplayName) , ( .NET 3.5):

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourDomain");

UserPrincipal up = UserPrincipal.FindByIdentity(ctx, "(your user name)");

if (up != null)  // we found the user
{
   up.DisplayName = "new display name for your user";
   up.Save();
}

! :-)

: NetBIOS (, "MICROSOFT"), DNS (microsoft.com) PrincipalContext.

!

.NET 2.0:

, .NET 2.0 "displayName" , "SAMAccountName" ( ):

// set the root for the search
DirectoryEntry root = new DirectoryEntry("LDAP://dc=yourcompany,dc=com");

// searcher to find user in question
DirectorySearcher ds = new DirectorySearcher(root);

// set options
ds.SearchScope = SearchScope.Subtree;
ds.Filter = string.Format("(&(sAMAccountName={0})(objectCategory=Person))", yourUserName);

// do we find anyone by that name??
SearchResult result = ds.FindOne();

if (result != null)
{
    // if yes - retrieve the full DirectoryEntry for that user
    DirectoryEntry userEntry = result.GetDirectoryEntry();

    // set the "displayName" property to the new value
    userEntry.Properties["displayName"].Value = yourNewUserFullName;

    // save changes back to AD store
    userEntry.CommitChanges();
}
+3

Source: https://habr.com/ru/post/1722973/


All Articles