Solved

Using a Space In a Batch Command Variable

Posted on 2004-09-22
10
3,298 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
 
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 83

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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 83

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

17 Experts available now in Live!

Get 1:1 Help Now