CorvettePower.COM
8Nov/04

Renaming a CN for a user in Active Directory

I actually found this little bit of code on another site. I don't take credit for it, but have used it quiet succesfully.

The problem with your vbscript is you can't change the cn attribute that way. You actually have to 'create' a new container and do a 'move', sort of. The following code should change all the names in a given OU for you, but please test of course!

Set objOU = GetObject("LDAP://ou=someou,dc=domain,dc=com")
objOU.Filter = Array("user")
For Each objUser In objOU
If objUser.cn = objUser.sn & " " & objUser.GivenName Then
     strNewPath = "CN="& objUser.samaccountname
     strCNName = objUser.cn
     Set cont = GetObject("LDAP://ou=someou,dc=domain,dc=com")
     Set newobj = cont.MoveHere("LDAP://CN="& strCNName &",someou,dc=domain,dc=com", strNewPath)
End If
Next

Original Post

Trackbacks are disabled.