Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using a Space In a Batch Command Variable

Posted on 2004-09-22
10
Medium Priority
?
3,341 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
ID: 12129966
Have you tried enclosing the path in quotes?

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

Author Comment

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

Expert Comment

by:Netman66
ID: 12130133
Set it as a constant.

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

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

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 51

Expert Comment

by:Netman66
ID: 12130146
Use this to test your script:



NewUser = "Me"

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

WScript.Echo Newfolder
WScript.Echo NewPath
0
 
LVL 85

Expert Comment

by:oBdA
ID: 12130838
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
 
LVL 1

Author Comment

by:Grime121
ID: 12135123
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 85

Accepted Solution

by:
oBdA earned 1500 total points
ID: 12135308
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
ID: 12135396
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
ID: 12135428
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
ID: 12135837
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

886 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