Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the following command to create 15 user accounts:

FOR /L %i in (1,1,15) DO dsadd user "cn=Grade 6 Student %i,ou=Accounts Student,OU=School Name, dc=curric,dc=schoolname,dc=wan" -samid g6%i -upn g6%i@curric.schoolname.wan -fn "Grade 6" -ln "Student %i" -display "Grade 6 Student %i" -pwd 1234 -disabled no

And it works well. I've added the following to the end, to try and provide the user's home drive settings:

-hmdrv H: -hmdir "\\servername\2013 Students\%username%"

That fills in the Home Folder fields in the ADUC user profile tab nicely, but substitutes %username% for my logged in account name (the account name I'm logged in with when I run the dsadd command) and not the user account name I create.

Is there a way I can get it to name the home folder as the created user account name and not the name of the account used to run the dsadd command?

share|improve this question

Yeah, %username% is interpreted at the command line to be your user account, the user account who is currently executing the command. Try using $username$ instead. Furthermore, I think dsadd might still be bugged, in which case you should be able to work around it by creating the user with dsadd, then setting the home directories with dsmod.

Since you're on 2008 R2, I'd personally recommend using Powershell (and the MS Active Directory cmdlets) going forward. Microsoft is pouring way more effort into Powershell these days than crusty old dsadd.exe.

The comments on this Microsoft page really hint to me that dsadd is still bugged. People having the exact same issue with it that you are.

share|improve this answer

You want to use the same logic you used for -samid g6%i. So the result would be -hmdrv H: -hmdir "\\servername\2013 Students\g6%i", no different than any other for loop variable.

And @ryanrias is correct, you really want to be using PowerShell and the New-ADUser cmdlet for something like this. It will change your life, it really is that good.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.