Click here to Skip to main content
Sign Up to vote bad
good
Hi all,
 
The issue I have come across arose from people in our Active Directory changing their name due to marriage. With a system I developed that allows our HR department to manage the AD User access I hit the issue of what to do when that happens, technically they need a new account and until now that was the process but managing to keep the SID of the user object would be really handy to deal with any odd file permissions lingering somewhere on the network (Before anyone says yes I know it should all be groups but... Can't be perfect all the time =P )
 
So this is the code I have to attempt a object name change, the CN rename and DN rename works fine, but it blows up when it has to start playing with the sAMAccount and userPrinciableName
 
            
Dim UserOBJChange As DirectoryEntry = GetUser(Username)
            UserOBJChange.Rename("CN=" & UserCN)
            UserOBJChange.CommitChanges()
 

            Dim UserOBJ As DirectoryEntry = GetUser(Username)
            Try
                SetProperties(UserOBJ, "givenName", FirstName)
                If MiddleInitial <> "" Then
                    SetProperties(UserOBJ, "initials", MiddleInitial)
                End If
                SetProperties(UserOBJ, "sn", LastName)
                SetProperties(UserOBJ, "mail", Email)
                SetProperties(UserOBJ, "displayName", displayNameAD)
                SetProperties(UserOBJ, "userPrincipalName", NewUsername + Domain)
                SetProperties(UserOBJ, "sAMAccountName", NewUsername)
                UserOBJ.CommitChanges()
 

 
            Catch ex As Exception
                Throw New Exception("User cannot be updated" & ex.Message)
            End Try
 
Commenting out the sam and principle and the code works fine, but that is 50% of the reason I want to change things...
 
The error message that is returned is the following:
 
User cannot be updatedThe server is unwilling to process the request. (Exception from HRESULT: 0x80072035)
 
And tips would be great!
 
Regards,
 
Caz
Posted 6 Mar '12 - 11:40

Comments
Volynsky Alex - 10 Aug '12 - 10:05
Nice question Zac!

2 solutions

What needed to happen is that the CN needed to be changed in one function and then that function research the user based on CN before trying to edit any other information.
  Permalink  
Searching in google gave me this[^]. Its written on C# though.
  Permalink  
Comments
Zac Newman - 7 Mar '12 - 0:17
Heya Walter, I stumbled across that myself, it is mainly addressing the issue of changing the CH and AD getting cranky over that. My rename function works well in dealing with the CN and DN. It is more the sAMAccount I have issues with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 388
1 OriginalGriff 291
2 Mayur_Panchal 153
3 Mohammed Hameed 145
4 Dave Kreskowiak 125
0 Sergey Alexandrovich Kryukov 8,146
1 OriginalGriff 6,236
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 10 Aug 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid