Solved

Using a Space In a Batch Command Variable

Posted on 2004-09-22
10
3,312 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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 84

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 84

Accepted Solution

by:
oBdA earned 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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