Need script to map home drive based on user input location


done a search and haven't found anything exactly like what I'd like to do.

We have a single domain with users in multiple locations. Each main location has its own file server and users map their home drive based on their location. We've had issues with home drives not mapping in remote locations that do not have a local server. We believe it may be timing out, that issue is being looked into.

Rather than have our IT staff manually map the drives, I'd like to do a small script we could place on their desktop that allows users to put their primary location, which would then map their home drive to the correct server.  Something like this.

Please select your primary location:
0 = HQ
1= Region 1
2= Region 2
3 = Region 3
4 = Region 4

Based on their answer I assume it would then run a command

Net Use K:\\hqserver\vol\%username%

Reg 1
Net Use K:\\r1server\vol\%username%

Reg 2
Net Use K:\\r2server\vol\%username%

Reg 3
Net Use K:\\r3server\vol\%username%

Reg 4
Net Use K:\\r4server\vol\%username%

I've tried writing a few, but scripting is definitely not a strong suit. I'm sure it would take a talented scripter about 2 minutes.

DTSC-OEIMNetwork AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this

@echo off
echo 0 = HQ
echo 1 = Region 1
echo 2 = Region 2
echo 3 = Region 3
echo 4 = Region 4

SET /P location=Please select your primary location: 

if %location% equ 0 Net Use K: \\hqserver\vol\%username%& goto :eof

if %location% equ 1 Net Use K: \\r1server\vol\%username%& goto :eof

if %location% equ 2 Net Use K: \\r2server\vol\%username%& goto :eof

if %location% equ 3 Net Use K: \\r3server\vol\%username%& goto :eof

if %location% equ 4 Net Use K: \\r4server\vol\%username%& goto :eof

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DTSC-OEIMNetwork AdministratorAuthor Commented:
Thanks for the quick reply, I'll test it out.
David Johnson, CD, MVPOwnerCommented:
in group policy you also have SITES use this to create a gpo for each site that has the folder location
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Mal OsborneAlpha GeekCommented:

1. Set up DFS, and let Windows do all that tricky stuff for you.
2. Set up GPOs tied to site, and have them either map via preferences, or fire a logon script.
Mal OsborneAlpha GeekCommented:
Here is some info on how DFS Replication works.

Basically, you set up several shares on multiple servers that are automatically synced in the background. So, maybe

If a file is changed in any of these shares, the changes are replicated to the rest. Client machines use site information to connect to the "closest" server.
DTSC-OEIMNetwork AdministratorAuthor Commented:
Tweaked it for my environment and so far testing with a few staff has worked like a charm. Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.