How to map network drives using AD

Posted on 2008-11-13
Last Modified: 2012-05-05
I have been asked by my company to map drives using active directory but i have never had to do this before. At the moment i have created my own OU but i just dont know where to start. My knowledge on batch files is next to none and my knowledge on VB is even worse. I have managed to go into the logon template in the group policy for the OU but i am just lost on what to do.

Can you please help

Question by:ciscocharlie
    LVL 70

    Expert Comment

    Use Group policy to ally a logon script to the OU, all users with accounts in the OU will then have the policy (and script) applied

    Are you trying to ma the same drives for all users or different drives for different users ?
    LVL 24

    Accepted Solution

    Here is a script I use to map drives and printers based on group membership. Just rename the case statements to the groups you want and the location of the shares. This should be a easy script for you to modify. Just apply this script as the login script under group policy.
    I hope this helps. Good luck.

    ' VBScript to map drives based on group membership
    On Error Resume Next
    Set WshNetwork = CreateObject("WScript.Network")
    DomainString = WshNetwork.UserDomain
    UserString = WshNetwork.UserName
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
    'unmap all drives
    WshNetwork.RemoveNetworkDrive "V:",true,true
    WshNetwork.RemoveNetworkDrive "W:",true,true
    WshNetwork.RemoveNetworkDrive "X:",true,true
    For Each GroupObject In UserObj.Groups
    	Select Case GroupObject.Name
    		Case "Group 1"
    			WshNetwork.MapNetworkDrive "Z:", "\\<Server>\<Share>"
    			wshNetwork.AddWindowsPrinterConnection "\\<Server>\<Share>"
    		Case "Group 2"
    			WshNetwork.MapNetworkDrive "Y:", "\\<Server>\<Share>"
    		Case "Group 3"
    			WshNetwork.MapNetworkDrive "X:", "\\<Server>\<Share>"
    	End Select

    Open in new window

    LVL 13

    Assisted Solution

    Copy the line below, open notepad, paste the line below, save file as map.bat (save as  all files in notepad)
    net use x: \\servername\sharename11 /persistent:yes
    net use y: \\servername\sharename12 /persistent:yes
    There are a few ways to do this, but for all users to get these mappings on logon, place the map.bat file into \\YourDomainControllerServername\netlogon\map.bat and set the users to run it automatically when they logon through their profile
    LVL 3

    Assisted Solution

    LVL 4

    Assisted Solution

    Good info about GPO local and AD setup

    Depending on how many mapped drives you need the simples would be leegclystvale but that would be for everyone, like to a public share; a more complex mapped drives would be andrew_aj1 more like departmental drives.

    Author Comment


    Thank you all for your replies.  I will be looking at this when i go back to work but i have one more question, can you tell me how to publish network printers through the GPO  so that certain departments can access the printers i wont them too, would i have to use a .bat file??????

    Thanks inadvance


    LVL 13

    Expert Comment

    Yes you could. Put a bat file in the Logon script part of the GPO for certain computers. You would need your AD OU structure to be organised by similar computers needing the specific printers or a common user OU.
    GPO>User configuration>Windows settings>scripts>(logon/logoff)
    Put your batch files in \\dcname\sysvol\scripts and then po0int your logon files in GPO to this location.
    Hope that helps
    LVL 24

    Expert Comment

    My script above provides shares and printers by group names. hopefully that will work for you.

    Author Comment


    Thanks a lot for your last comment how would you create a batch file for the printers, i am a batch file novice.

    Assisted Solution

    This is the script that I use to map printers for teachers. I have it in a windows login batch file for my teachers GPO. Works great everytime. It set's the default printer as well to whatever printer number you like.


    ' PrinterSetDefault.vbs - Windows Logon Script.
    ' -----------------------------------------------------------'
    Option Explicit
    Dim objNetwork, strLocal, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strUNCPrinter4
    strUNCPrinter1 = "\\dhs01\BIC_OFFICE"
    strUNCPrinter2 = "\\dhs01\BIC_COLOR"
    strUNCPrinter3 = "\\dhs01\BIC_UPSTAIRS_PHOTO"
    strUNCPrinter4 = "\\dhs01\BIC_DOWNSTAIRS_PHOTO"
    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.AddWindowsPrinterConnection strUNCPrinter1
    objNetwork.AddWindowsPrinterConnection strUNCPrinter2
    objNetwork.AddWindowsPrinterConnection strUNCPrinter3
    objNetwork.AddWindowsPrinterConnection strUNCPrinter4
    objNetwork.SetDefaultPrinter strUNCPrinter1

    Open in new window


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Suggested Solutions

    Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now