How to map network drives using AD

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

Who is Participating?
andrew_aj1Connect With a Mentor Commented:
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

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 ?
leegclystvaleConnect With a Mentor Commented:
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
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

choswootConnect With a Mentor Commented:
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.
ciscocharlieAuthor Commented:

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


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
My script above provides shares and printers by group names. hopefully that will work for you.
ciscocharlieAuthor Commented:

Thanks a lot for your last comment how would you create a batch file for the printers, i am a batch file novice.
HRSBTechConnect With a Mentor Commented:
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

All Courses

From novice to tech pro — start learning today.