Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.