joeware - never stop exploring... :)

Information about joeware mixed with wild and crazy opinions...

I need to rename the DN on all of my users from Smith, John to the sAMAccountName…

by @ 1:21 pm on 9/9/2009. Filed under tech

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=*,*)" samaccountname

AdFind 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=loc

dn:CN=some\, user,CN=Users,DC=test,DC=loc
>sAMAccountName: ThisTestUser

1 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 1000

AdMod V01.10.00cpp Joe Richards (joe@joeware.net) February 2007

DN Count: 1
Using server: r2dc1.test.loc:389
Directory: Windows Server 2003

Renaming 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 samaccountname

AdFind 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=loc

dn:CN=ThisTestUser,CN=Users,DC=test,DC=loc
>sAMAccountName: ThisTestUser

1 Objects returned

Rating 4.00 out of 5

Comments are closed.

[joeware – never stop exploring… :) is proudly powered by WordPress.]