Solved

Using a Space In a Batch Command Variable

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

772 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