Solved

Remapping network drives

Posted on 2009-05-14
16
1,042 Views
Last Modified: 2012-05-07
I am in the process of implementing DFS Namespaces and I have clients that have network drives mapped to four different file servers.  I need some sort of script (powershell, vbs, etc.) that will remap the old file server name to the new DFS namespace with little or no impact to clients.
0
Comment
Question by:candlends
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
16 Comments
 
LVL 6

Expert Comment

by:Lunda_Construction
ID: 24389235
Change it in the logon script, then have each user restart.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 24389284
The NET USE command in the login script should do what you want.

The syntax of this command is:


NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]
0
 

Author Comment

by:candlends
ID: 24389420
The net Use command won't work because I have hundreds of clients each with unique network drive mappings that have to be remapped.  I need a script that will look at the existing drive mappings and substitute the old server name for the new DFS namespace name.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 24389557
Aha. So you want to parse the output of NET USE...

And I'm on a standalone laptop at home ... no network.

Can you help by going to one of the clients and typing ...

NET USE > %TEMP%\MappedDrives.log

and then attach it here?

If you need to edit anything, simple replace the letters, don't delete them (just in case spacing is important).

So ...


PRIVATE

becomes

P*****E

for example.

0
 

Author Comment

by:candlends
ID: 24389722
I have attached the net use file.  The drive letters and network drive mappings are very diverse, practically unique for each user
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 24389795
So what criteria are you using for remapping?
0
 

Author Comment

by:candlends
ID: 24389913
I will be replacing the old server name (i.e. \\server1\networkpath, \\server2\networkpath, \\server3\networkpath, etc.) with the new DFS Namespace so the new drive mapping will \\dfsname\networkpath.  I hope that is what you mean by criteria?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 24390038
Yep.

File missing.

I have to go now.

If you can post the file, I can take a look at it tomorrow for you.
0
 

Author Comment

by:candlends
ID: 24396984
File doesn't seem to attach, here is the info in the file:

New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Disconnected I:        \\r*********1\its         Microsoft Windows Network
             K:        \\r******s.ads\netlogon\users
                                                 Microsoft Windows Network
Disconnected Z:        \\a****a\terminatedemployees$
                                                 Microsoft Windows Network
The command completed successfully.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 24397559
So,

i: => \\dfs\its
k: => \\dfs\netlogon\users
z: => \\dfs\terminatedemployees$

Or whatever mappings they have.

I'll create a test script tonight.

Now I'm at work, I have another example to work from (see snippet).

I think those ending in $ may be an issue (for me I'm connecting to the root of drives rather than hidden shared folders.

What do you want to happen for those mappings that cannot be performed?

Say there is no mapping available?

Also, if users have mapped to the root of the drives on the servers ...

\\server1\c$

for example, how do you want those handled?



New connections will be remembered.
 
 
Status       Local     Remote                    Network
 
-------------------------------------------------------------------------------
OK           I:        \\bv-cluster-file\department data
                                                 Microsoft Windows Network
OK           M:        \\bv-cluster-file\Data Management
                                                 Microsoft Windows Network
OK           N:        \\bv-cluster-file\network area
                                                 Microsoft Windows Network
Disconnected S:        \\bv-vm-svr-8\SageCCC     Microsoft Windows Network
Disconnected T:        \\bv-vm-svr-19\CCC2SQL    Microsoft Windows Network
OK           Z:        \\richardquadling\scratch$
                                                 Microsoft Windows Network
Disconnected LPT2      \\BV-CLUSTER-PRN\BV-DIR-PRN-1
                                                 Microsoft Windows Network
The command completed successfully.

Open in new window

0
 

Author Comment

by:candlends
ID: 24397775
Thanks for the help by the way!  You can probably disregard the shares ending in $ or root driives as it is not that common and can be dealt with in a one off fashion.  For those mappings that cannot be mapped the script should fail gracefully or just move onto the next share.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 24410490
Ok.

Thanks for that. I'll see what I can get to you today.
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 24421185
Sorry for the delay.Try this manually on a few workstations first. See what you think.The lines which have ...ECHO MAP ....are the actual mapping commands to drop and reconnect.The script also handles not dropping and reconnecting the mapping once it is on the named DFS.Just edit the 5th line to reflect the new DFS name.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM Edit the line below.
SET DFS=Distributed_File_System_Name_Goes_Here
 
REM Iterate the NET USE output
FOR /F "tokens=1,2* delims= " %%A IN ('NET USE') DO (
 
	SET TestLocal=%%B
	SET TestRemote=%%C
 
REM Remove the "Microsoft Windows Network" part if it is present as part of the Remote.
	IF "!TestRemote:~-25!"=="Microsoft Windows Network" (
		SET TestRemote=!TestRemote:~0,-25!
	)
 
REM Trim any whitespace
	CALL :_Trim !TestRemote!
	SET TestRemote=!TRIM_Response!
 
REM Only process Local Drives (not printers)
	IF "!TestLocal:~-1!"==":" (
 
REM Only process Remotes which are not mapped to hidden shares (Remote ends in $)
		IF NOT "!TestRemote:~-1!"=="$" (
			CALL :_Pos "!TestRemote!" \ 3
			CALL :_Split "!TestRemote!" !POS_Response!
 
REM Only process shares which are NOT already mapped to the DFS
			IF /I NOT "!SPLIT_Left!"=="\\!DFS!" (
				ECHO Drive !TestLocal! is currently mapped to "!TestRemote!"
				ECHO Drive !TestLocal! will be mapped to "\\!DFS!\!SPLIT_Right!"
				ECHO.
 
				ECHO NET USE /D !TestLocal!
				ECHO NET USE !TestLocal! "\\!DFS!\!SPLIT_Right!" /PERSISTENT:YES
				ECHO.
			)
		)
	)
)
GOTO :EOF
 
:_Trim
SET TRIM_Response=%*
GOTO :EOF
 
:_Pos
SET POS_Response=%3
SET POS_Work=%1
SET POS_Find=%2
:_PosLoop
IF "!POS_Work:~%POS_Response%,1!"=="%POS_Find%" GOTO :EOF
SET /A POS_Response+=1
GOTO _PosLoop
 
:_Split
SET SPLIT_Work=%~1
SET SPLIT_Right=!SPLIT_Work:~%2,255!
SET /A SPLIT_Work-=1
SET SPLIT_Left=!SPLIT_Work:~0,%2!
GOTO :EOF

Open in new window

0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 25057948
AngelIII, my script performs as I expect it to. It would be great to have some feedback from the OP to know if it is what they wanted.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

756 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