No announcement yet.

drive mapping different locations

  • Filter
  • Time
  • Show
Clear All
new posts

  • drive mapping different locations

    background first:
    2 locations, both have a DC running win 2k3. Main DC @ HQ, second at remote location. 2 sites connect currently via a VPN from DC-02 to DC-01, altho that may be changing.

    Several Users logon at both locations, including myself. Currently network drives are mapped by a logon script run by a GP. Is there a way of getting it to connect different drives at different locations? eg.@ HQ i'd have something like "net use s: \\DC-01\software" but that might not be able to reconnect at remote location so would like "net use s: \\DC-02\software"

    I think basically I want it to tell where I am and map accordingly.

    Also, out of interest, how would you guys connect 2 DC's on the same domain from different locations for best replication etc? I've got a fair idea what route I want to go down, but was wondering what others used.

  • #2
    Re: drive mapping different locations

    Regarding mapping drives, I would use DFS for this; traffic between sites will be reduced to the odd logon that didn't work locally and replication.

    Create a DFS root for the domain and add a DFS share for your data. Make sure that both sites' folders appear as replicas at the DFS Root. then your script would read:

    net use S: \\<domainname>\domainDFSrootname\DFSshareName /persistent:no

    It will use the local copy.

    Hope this helps...

    For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

    Anything you say will be misquoted and used against you


    • #3
      Re: drive mapping different locations

      If you dont want to use DFS you could always add some sort of check into your logon script which checks to see which DC you authenticated against using the %logonserver% variable i.e:

      If %logonserver% = x then net use x: \\servername\sharename
      net use x: \\differentservername\sharename
      Hope this helps

      Michael Armstrong
      MCITP: EA, MCTS, MCSE 2003, MCSA 2003: Messaging, CCA, VCP 3.5, 4, 5, VCAP5-DCD, VCAP5-DCA, ITIL, MCP, PGP Certified Technician

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **


      • #4
        Re: drive mapping different locations

        Good thinking Michael.

        Here's one that will do it based on the gateway of the computer.

        REM replace the IP address in the next line with your gateway address
        ipconfig | find "" && net use x: \\servername\sharename || net use x: \\differentservername\sharename
        or if you have more than two options

        REM replace the IP address in the next line with your gateway address
        ipconfig | find "" && (net use x: \\srv1\sharename & goto EOF) 
        ipconfig | find "" && (net use x: \\srv2\sharename & goto EOF)
        ipconfig | find "" && (net use x: \\srv3\sharename & goto EOF)
        REM etcetera
        But my code looks very inefficient to me. I'm still in the infant stages of scripting.
        Rems or somebody else will no doubt have a better script.

        EDIT - I should note that there's a potential issue if you are using subnetmasks of /25 or higher.
        To illustrate this lets say you have two networks with a /25 mask;
        Network 1 - gateway
        Network 2 - gateway

        Now lets say that you have a computer on network 2 with an IP address of
        If I was to run following script it would map the drive to the incorrect server for the subnet because the find command just looks for a text string and therefore matches the search for ""
        ipconfig | find "" && net use x: \\servername\sharename || net use x: \\differentservername\sharename
        But if you're using a mask of /24 or lower then the above won't be an issue.
        Last edited by JeremyW; 14th April 2007, 06:04. Reason: Too much code! ;)

        Network Consultant/Engineer
        Baltimore - Washington area and beyond


        • #5
          Re: drive mapping different locations

          I think using dfs is the best solution, but you need the enterprise ed. to use dfs that way.
          By using dfs the shares will be synchronized automatically.

          When you choose a unc solution, then find an other way to synchronize the shares (like using a RoboCopy script).
          If you do not want to synchronize the shares, why do you want the same drive letters?

          Michael's solution is nice and fast:
          rem Conditionally perform commands...
          :: dc1 and server1 are the names of servers on site1 
          :: dc2 and server2 are the names of servers on site2 
          If /I %LOGONSERVER% EQU \\DC1 (net use x: \\servername1\sharename & GoTo Next1)
          If /I %LOGONSERVER% EQU \\DC2 (net use x: \\servername2\sharename & GoTo Next1)
          Other ways to determine the site the computer belongs to can be found in this article:

          But can't you simply use the site level in GPMC and link different gpos (user configuration enabled) to each site? ?


          Comparing gateways is also good thinking, I think by using ipconfig the batch possibly can run faster then when using nltest.exe.
          EDIT 16th April - tested it, in my situation it turned out that nltest.exe was in fact slightly faster.

          To solve the issues you mensioned,
          If you use FINDSTR you can in this case add a $ at the end of the ipaddress "$" OR
          in all cases using FINDSTR you can use \< for setting the beginning and \> to set the exact end of the whole word.
          e.g.---> ipconfig | Findstr /i "\<\>" >Nul <---this sets an %errorlevel% [0,1] that can be used by If-Then-Else

          EDIT - I deleted the previous suggestion to use FIND with a space at the end of the ipaddres (" "), didn't seem to work in this case, because the ipaddress is at the end of the line.
          So is best to use FINDSTR (=only supported in Windows XP and newer).

          Or you can set a %Site% OR a %Gateway% variable (that variable can be use as %logonserver% in previous example)
          FOR /F %%A IN ('nltest /dsgetsite ^| Find/v " "') DO SET Site=%%A||REM
          (I added ||REM at the end of the command-line, just to be sure no space can be typed on the end of the SET command)

          FOR /F "tokens=2 delims=:" %%A IN ('ipconfig ^| Find/i "gateway"') DO SET Gateway=%%A||REM
          Set Gateway=%Gateway:~1%||REM
          '<- extra SET Gateway= line to remove a space that was at the beginning'.

          Use the 'method for getting a site indentifier' only once in a batch, because it can slowdown the batch. In this case there are only two sites, so you could use ELSE. If there are more sites (or no sites as third option), then consider to set a %variable%, that way the script can call the faster variable for the If-Then commands.

          Here is also an example of a VBScript as logon script to determine the site first, then in this example it will run the right batch files for each site:
          '// VBS - Determine the *Site* this computer is registered to
          On Error Resume Next
          Dim objShell:Set objShell=CreateObject("Wscript.Shell")
          Set objADSysInfo = CreateObject("ADSystemInfo")
          Select Case objADSysInfo.SiteName
            Case "Site1"
                  objShell.Run "%comspec% /c \\..\...\batchForSite1.cmd",0
            Case "Site2"
                  objShell.Run "%comspec% /c \\..\...\batchForSite2.cmd",0
            Case Else 'no site? then Shutdown the client (LOL)
          End Select
          Set objShell = Nothing
          Last edited by Rems; 16th April 2007, 14:14. Reason: added %variable% examples ,,, next: little correction to the vbscript ,,, next: tested ipconfig.exe vs nltest.exe

          This posting is provided "AS IS" with no warranties, and confers no rights.


          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts


          • #6
            Re: drive mapping different locations

            ok i think i agree with dfs, having had a quick look into it.

            I would ideally now like several shares (for each dept.) that will replicate themselves at each location. eg. the shares \\DC-01\Software & \\DC-02\Software to be one and replicate themselves across.

            trouble now is that I'm having difficulty setting dfs up, something else I have little experience in. I'll have another search on google and here for advice, but if I cant find any i'll come back for help!


            • #7
              Re: drive mapping different locations

              Still got a problem with DFS. I think its probably best if I start a thread in the right place about this tho, as its not really anything to do with scripts anymore....

              Cheers for the help tho guys.