Solved

Remapping network drives

Posted on 2009-05-14
16
1,036 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:RQuadling
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
 
LVL 40

Expert Comment

by:RQuadling
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:RQuadling
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 40

Expert Comment

by:RQuadling
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:RQuadling
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:RQuadling
ID: 24410490
Ok.

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

Accepted Solution

by:
RQuadling 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:RQuadling
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Microsoft has released remote PowerShell capabilities to all commercial Office 365 customers. So you can be controlled via PowerShell and not from the Office 365 admin center Download Windows PowerShell Module for Lync Online http://www.micros…
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)…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now