ADMod, ADFind – user rename

Reading Time: < 1 minute

Another quick and dirty example how one can user ADMod and ADFind to do something in AD quickly and without scripting. This time question is – how to rename users account, with rename I understand changing their RDN in directory? I will use ADFind to find users and prepare input for ADMod like I did it last time, and then I will use -rename switch of ADMod to rename users.

So If we want to set RDN to samAccountName value we should do something like this:

adfind -b “OU=Employees OU,DC=W2k,DC=PL” -s subtree -f “(&(objectClass=user)(objectCategory=person))” samaccountname -adcsv | admod -rename {{samaccountname}}

 

If we want more familiar value in RDN like <surename>.<given name>, we can do something like this:

adfind -b “OU=Employees OU,DC=W2k,DC=PL” -s subtree -f “(&(objectClass=user)(objectCategory=person))” sn givenname -adcsv | admod -rename {{sn}}.{{givenname}}

Simple, nice, quick and doesn't require scripting :).