Solved

Using a Space In a Batch Command Variable

Posted on 2004-09-22
10
3,290 Views
Last Modified: 2012-06-27
This is what I have:

set NewFolder=\\PENGUIN\VOLUNTEER FILES\%NewUser%

dsadd user "%DisplayName%" -samid %NewUser% -upn %UPN% -fn "%FirstName%" -ln "%LastName%" -display "%DisplayName%" -pwd "%Password%" -hmdir "%NewFolder% -hmdrv Z: -mustchpwd yes -disabled no

It's not letting me use -hmdir "%NewFolder%" because of the space!!!!!! What's really frustrating is I had it working beautifully until I accidentally deleted the entire script by accident earlier today!! Now I can't figure out what I did to make this work before. Help?
0
Comment
Question by:Grime121
  • 5
  • 3
  • 2
10 Comments
 
LVL 51

Expert Comment

by:Netman66
Comment Utility
Have you tried enclosing the path in quotes?

set NewFolder = "\\PENGUIN\VOLUNTEER FILES\%NewUser%"
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
yeah. When I do that and then ECHO %NewFolder% it shows that it's including the quotes.
0
 
LVL 51

Expert Comment

by:Netman66
Comment Utility
Set it as a constant.

Const NewFolder = "\\PENGUIN\VOLUNTEER FILES\"

The variable will need to be "added" to the path.

0
 
LVL 51

Expert Comment

by:Netman66
Comment Utility
Use this to test your script:



NewUser = "Me"

Const NewFolder = "\\PENGUIN\VOLUNTEER FILES\"
NewPath = NewFolder+NewUser

WScript.Echo Newfolder
WScript.Echo NewPath
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Quotation marks around the complete path should work quite well; assuming that you did a copy and paste of that line, the error is rather simple: the closing quotation marks in your hmdir specification are missing: -hmdir "%NewFolder% instead of -hmdir "%NewFolder%".
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:Grime121
Comment Utility
Sorry for the late response. I I noticed that too. It was just a typo when I was trying to make it work. I added the quotation mark and it still didn't work.

I'm not quite following you, Netman. This is a batch script, not a vb script (which I think that code is for).


Here is the output when I REM @ECHO OFF:

C:\Documents and Settings\Administrator\Desktop>SET NewFolder=\\PENGUIN\VOLUNTUNTEER FILES\test

C:\Documents and Settings\Administrator\Desktop>ECHO \\PENGUIN\VOLUNTUNTEER FILES\test
\\PENGUIN\VOLUNTUNTEER FILES\test

C:\Documents and Settings\Administrator\Desktop>dsadd user "TestFN TestLN" -samid test -upn test@<mydomain.local> -fn "TestFN" -ln "TestLN" -display "TestFN TestLN" -pwd "temp" -hmdir "\\PENGUIN\VOLUNTUNTEER FILES\test" -hmdrv Z: -mustchpwd yes -disabled no
dsadd failed:Value for `Target object for this command' has incorrect format.type dsadd /? for help.

C:\Documents and Settings\Administrator\Desktop>IF NOT EXIST "\\PENGUIN\VOLUNTUNTEER FILES\test" md "\\PENGUIN\VOLUNTUNTEER FILES\test"
The network path was not found.

C:\Documents and Settings\Administrator\Desktop>cacls "\\PENGUIN\VOLUNTUNTEER FILES\test" /t /e /g <mydomain>\test:F
No mapping between account names and security IDs was done.
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
Hm; have you noticed that the variable is set to VOLUNTUNTEER (not the additional "TUN"), or is that a typo again?
Then the name of the user object you're creating isn't correct.
The necessary DN for your new user should look something like "cn=TestFN TestLN,ou=Users,dc=your,dc=domain,dc=local"
Run the command
dsquery user
to get a list of existing users and the necessary format of the DN.
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
Man... I'm bad today. That was another typo. That got rid of the "network path not found" error, but dsadd is still failing. When I remove that -hmdir option it works fine though.

The DN is "CN=TestFN TestLN,OU=Volunteers,DC=<mydomain>,DC=local". It's the same format as all of the others.
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
wow, wait a second. I take that back. I took out all of the directory stuff in the dsadd line, and it gave the same error. It must be something else.
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
Ok, I got it. I was trying to put just the user's name in when I should of had their full DN for dsadd user <User's DN>. After I fixed that there were a few other trivial errors dealing with the the %JoinGroupDN% variable that I added. It was simple to fix though. I'm going to award oBdA the points because your input made me look closer at the DN's I was using, which was were the problem actually lay.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now