Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've written a small batch file to help us with a server migration to remap user directories using GPO.

However in the batch file I'm having a syntax problem that appears right but it's still failing. Here is what I have so far below.

If exist "\\server\UserData\%username%"     
GOTO :UNMAP    
ELSE    
NET USE H: \\newserver\UserData\%USERNAME%    
:UNMAP    
NET USE H: /DELETE /Y    
NET USE H: \\newserver\UserData\%USERNAME%

Now when I run it I get the following:

The syntax of the command is incorrect.
C:\>if exist "\\server\UserData\userfolder"

Any idea how to resolve this or what I am doing wrong?

share|improve this question

1 Answer 1

goto :unmap should be on the same line as the if

even better, simplify the whole thing like this:

If exist "\\server\UserData\%username%\." NET USE H: /DELETE /Y
NET USE H: "\\newserver\UserData\%USERNAME%"
share|improve this answer
    
Awesome that fixed that line. Now it's barking at my else command. So I tried moving the lower line up below the else as well thinking that would be the same thing but that didn't work. –  Chad Aug 3 '12 at 20:08
    
Get rid of ELSE altogether. Instead, put in a GOTO after your first NET USE line that skips the :UNMAP section. –  nedm Aug 3 '12 at 20:38
    
you don't need the goto line at all. Longneck's script by itself should do what you want it to do. It removes the drive mapping if it's there and then maps the drive you want to the new server. –  Rex Aug 3 '12 at 20:58
1  
frankly, you don't even need the if. just blindly delete the h: drive. you're going to remap it on the next line, so who cares if it returns an error? –  longneck Aug 3 '12 at 21:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.