Is it possible to change the common name in Active Directory via script? The problem that I have is a common name such as Doe, John T. is returned as cn=Doe\, John T.
The "\" causes some problems for some other scripts that we use. I can obviously change the name via AD users and computers by right clicking on it and choosing "rename" but I have many to change and would like to do it with a script. Before I get to carried away with the script, I wanted to try something simple just to test. Here's what I used:
For Each $user in $target If $user.name = "cn=Doe\, John T." $newname = "cn=John T. Doe" $user.name=$newname $user.SetInfo ? 'Error = '+@ERROR+' - '+@SERROR ?"New name is: "$user.name EndIf Next
If I run this script, it will find cn listed above, but using user.SetInfo returns the following error: Error = -2147352562 - Invalid number of parameters. Any help would be greatly appreciated.
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
JohnQ, I saw your post last night and will be able to respond after doing some testing. Unfortunately, I will not have time until after work. If no one responds by then, look for my post this evening.
I'm getting the same thing when I try it with my name. But I don't think it is necessarily a SetInfo issue, because I get the same error if i put an @serror after the assignment
code:
$user.name=$newname @serror
And i haven't had any trouble changing other properties with the same script.
Since you are attempting to actually rename the object not a truly modifyable attribute, I do not think your approach will work. CN is part of the distinguished name that is the object. You will probably want to use the MoveHere method to move the object to the same container with a new name.
Howard, when you right click on a name in AD users and computers and choose rename, aren't you actually renaming or "modifying" the CN? Do you feel that the MoveHere method is the best (if not the only) approach? It seems simple enough.
Thanks for your help -- you've always got the good answers. Is there a good resource that one can go to for some of these differnt methods and object properties. Just when I think I've figured something out, you come up with something new.