Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


How to Rename an Account

 Keywords:  ADSI CN Rename Account in a Mixed Domain

Question:

Please can you advise how I can rename an Active Directory Account. There does not seen to be any function in the ADSI extender to do this. You can't change the CN property as that will fail.

Microsoft does allow renaming so if it can't be done via ADSI extender presently, can it be added in the near future.

Thanks

Answer:

After researching the issue I found the best code for renaming a user in AD domain:
AddExtender("WWADS34I.DLL")
AddExtender("WWWNT34i.DLL")

;Change display name
errormode(@off)
sAdsiPath ="LDAP://server/cn=users,dc=domain,dc=com" 
dsSetCredent("domain\administrator", "password")
sEmpireGroup = dsFindPath(sAdsiPath , "CN=olduser")
dsSetProperty(sEmpireGroup, "givenname", "newuser")
dsSetProperty(sEmpireGroup, "userprincipalname", "newuser@domain.com")
dsSetProperty(sEmpireGroup, "displayname", "newuser")
sNewPath = dsMoveObj(sEmpireGroup, sAdsiPath, "cn=newuser")

;Check if change ok?
sEmpireGroup = dsFindPath(sAdsiPath , "cn=newuser")
slist = dsGetProperty(sEmpireGroup, "name")
if slist <> "newuser" then 
message("","error") 
else
message("","User renamed!") 
end if
errormode(@cancel)

;Change full name
wntUserSetDat("\\%server1%","olduser","full_Name","newuser",0)

;Change login name
wntUserRename("\\%server1%", "olduser", "newuser" ,0)

Article ID:   W15045