Script Center > Scripting Forums > The Official Scripting Guys Forum! > Need to remap network drives to DFS
Ask a questionAsk a question
 

QuestionNeed to remap network drives to DFS

  • Wednesday, October 28, 2009 6:41 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    We are moving over to DFS namespace and I need to create a script that will remap our users that have network drives to DFS. Has anyone created a script for that?

All Replies

  • Wednesday, October 28, 2009 9:10 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    If you want to use a WSH script, check out the WshNetwork object's EnumNetworkDrives method. Using this method, you can detect what drives are mapped, and to where. You can then use the RemoveNetworkDrive method to remove the old drive mapping and the MapNetworkDrive method to map the drive to the new location.

    Bill
  • Thursday, October 29, 2009 4:44 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Where in this script would I apply the "RemoveNetworkDrive"?  I am not an expert in VB.  Any help would be appreciated?

  • Thursday, October 29, 2009 6:39 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Do you have any experience in writing VBScript scripts? If not, then I recommend you get a good book and/or some training.

    Bill
  • Thursday, October 29, 2009 7:23 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Here's what I have so far..

    If StrComp("x:", \\servername\) = 0 Then

      'remove the existing share
      objNetwork.RemoveNetworkDrive "x:", True, True
      objNetwork.RemoveNetworkDrive "m:", True, True  
      'give operation a moment to finish
      wscript.sleep 200
    end if

      'remap the drive to the new server
      objNetwork.MapNetworkDrive "x:", \\company\dfsroot
      objNetwork.MapNetworkDrive "m:", \\company\dfsroot

    It still does not map to the DFS.  Any suggestions on what the script?  Any help would be appreciated. Thanks

  • Thursday, October 29, 2009 8:04 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    Here's the rough approach I would use:

    Dim WshNetwork, Drives, N, Drive, UNCPath
    
    Set WshNetwork = CreateObject("WScript.Network")
    Set Drives = WshNetwork.EnumNetworkDrives
    For N = 0 To Drives.Count - 1 Step 2
      Drive = Drives.Item(N)
      UNCPath = Drives.Item(N + 1)
      Select Case Drive
        Case "X:"
          If LCase(UNCPath) = "\\server\share1" Then
            WshNetwork.RemoveNetworkDrive "X:", True, True
            WshNetwork.MapNetworkDrive "X:", "\\dfsroot\path 1"
          End If
        Case "Y:"
          If LCase(UNCPath) = "\\server\share2" Then
            WshNetwork.RemoveNetworkDrive "Y:", True, True
            WshNetwork.MapNetworkDrive "Y:", "\\dfsroot\path 2"
          End If
      End Select
    Next
    

    HTH,

    Bill
  • Friday, October 30, 2009 1:01 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks I'll try from here.  I'll follow up with if successful or not.

  • Friday, October 30, 2009 7:26 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The x: file ran flawlessly.  The y: is a user's folder redirect, in other words the user has a username folder(on the file server) that is redirected to their desktop.   Any suggestions.
  • Friday, October 30, 2009 7:32 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Are you talking about folder redirection from a GPO?

    Bill
  • Friday, October 30, 2009 8:03 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Correct? 

  • Friday, October 30, 2009 8:08 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Correct!
  • Friday, October 30, 2009 8:09 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Then isn't the fix to correct the setting(s) in the GPO?

    Bill
  • Tuesday, November 03, 2009 3:03 PMJonesy77 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The redirect folder is correct in our GPO.  I've applied this script to a GPO and have it pointing to my test OU.  I get the same results.
  • Tuesday, November 03, 2009 3:16 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, please post the GPO settings you are using, and the code that is not working. If you get an error message, please post the exact error message (including line number).

    Bill