This is quick and easy with AdFind and AdMod…
You just have to find the users, pipe their DN and sAMAccountName to AdMod and tell it to do a rename… Like so
adfind –b ou=someou,dc=domain,dc=com -f "&(objectcategory=person)(objectclass=user)(name=*,*)" samaccountname –adcsv | admod –rename {{samaccountname}} –upto 1000
That command self limits itself to only modifying up to 1000 users just in case something isn’t right. You can set that limit to whatever you want or specify –unsafe instead if you just want them all done and are sure your query is ok.
Here is a live example:
[Wed 09/09/2009 13:04:47.87]
G:\>adfind –b cn=users,dc=test,dc=loc -f "&(objectcategory=person)(objectclass=user)(name=*,*)" samaccountnameAdFind V01.40.00cpp Joe Richards (joe@joeware.net) February 2009
Using server: r2dc1.test.loc:389
Directory: Windows Server 2003
Base DN: cn=users,DC=test,DC=locdn:CN=some\, user,CN=Users,DC=test,DC=loc
>sAMAccountName: ThisTestUser1 Objects returned
[Wed 09/09/2009 13:04:53.88]
G:\>adfind –b cn=users,dc=test,dc=loc -f "&(objectcategory=person)(objectclass=user)(name=*,*)" samaccountname -adcsv |admod -rename {{samaccountname}} -upto 1000AdMod V01.10.00cpp Joe Richards (joe@joeware.net) February 2007
DN Count: 1
Using server: r2dc1.test.loc:389
Directory: Windows Server 2003Renaming CN=some\, user,CN=Users,DC=test,DC=loc to ThisTestUser…
The command completed successfully
[Wed 09/09/2009 13:04:59.93]
G:\>adfind –b cn=users,dc=test,dc=loc -f samaccountname=thistestuser samaccountnameAdFind V01.40.00cpp Joe Richards (joe@joeware.net) February 2009
Using server: r2dc1.test.loc:389
Directory: Windows Server 2003
Base DN: cn=users,DC=test,DC=locdn:CN=ThisTestUser,CN=Users,DC=test,DC=loc
>sAMAccountName: ThisTestUser1 Objects returned