How to change username in Active Directory

I want to change the user .NET applications from Active Directory in my application.

Now I change it like this:

DirectoryEntry userToUpdate = updatedUser.GetDirectoryEntry(); userToUpdate.Properties["sAMAccountName"].Value = user.NewLogin; userToUpdate.CommitChanges(); 

But it does not work as I expect. When I check the "Active Directory Users and Computers" entry for this user, then on the "account" tab, I see that:
- The "Username" property is not updated
- Fixed updating the property "Login to login (pre-Windows 2000)."

How to update username in AD from C # code? What property should I set in DirectoryEntry, or is there another way to change the username.

+4
source share
3 answers

There are two login names in AD:

 sAMAccountName = User logon name, (pre-windows 2000) Format/Usage: domain\user.name (note, your code will only populate user.name) userPrincipalName = User logon name Format/Usage: user.name@domain.local 

You need to update both.

+7
source

Try userPrincipalName instead of sAMAccountName .

+1
source

Here is a really good link that you can link to, be sure to check the bottom of the page to see its full use

Everything in Active Directory through C # .Net 3.5 (Using System.DirectoryServices.AccountManagement)

0
source

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


All Articles