Solved

Remapping network drives

Posted on 2009-05-14
16
1,038 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
  • 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
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)

 
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

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.

Question has a verified solution.

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

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

810 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