Link to home
Create AccountLog in
Avatar of jacogist

asked on

How do I use spaces in DSADD to bulk import users

I have been using dsadd for a while now with almost no problems, until today. I've always used identification numbers for the CN, but today I need to use FN LN. My problem comes in with the way I run the command, and I cannot find a way around this issue. The moment I have the space in the txt file, it automatically jumps from %%A to %%B. I have included an example of the two "batch" files below.

The Command:

for /f "tokens=1-6" %%A in (AllUsers.txt) do (dsadd user %%A -fn %%B -ln %%C -samid %%E -upn %%E@contoso.local -hmdir %%G -hmdrv h: -pwd 12121)

The List file:

"CN=John Doe,OU=Computer,OU=staff,OU=compname,DC=contoso,DC=local"      John      Doe      doej      doej@contoso.local      \\servername\useraccounts\staff\doej      H:

Is there a better way of doing this? I mostly use this when we have to recreate the AD structure, or redo the server without having an usuable backup of the AD.
Avatar of oBdA

You need to have the list file tab separated (or any other character that is NOT appearing in the rest of the strings).
Then use
for /f "tokens=1-6 delims=[TAB]" %%A in (AllUsers.txt) do (dsadd user %%A -fn %%B -ln %%C -samid %%E -upn %%E@contoso.local -hmdir %%G -hmdrv h: -pwd 12121)

Open in new window

(Obviously you'll have to replace [TAB] with a real tab in your editor).
Avatar of Krzysztof Pytko
Krzysztof Pytko
Flag of Poland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jacogist


Thanks, works perfectly.
Great! You're welcome :)