Mapping Network Drives

From Wiki

Jump to:navigation, search

Script Language: .bat

This page will teach you how to map network drives The code below will disconnect any network drives from the previous session. You will place this at the top of the script.

The code below will map your drives. You simply change your server path to suite your network. To change the drive letters you will change the V & W just after “net use”. To add more drives simply add more lines to the script.

<vb> net use * /d /y net use V: "\\servername\Network Drives\Media" net use W: "\\servname\ICT Storage" </vb>

This line of code will disconnect network drives from the previous session <vb> net use * /d /y

</vb>

Please Note:

I strongly recommend you do not map drives to the following drive letters

A B C D E

This is because drive C Is usually the local disc, drive A & B floppy drives, D & E are usually used for optical drives or USB pen drives.


Script Language: .vbs

Drive Mapping Example

Checks to remove network drives first then applys drives depending on the group your are assigned to in AD.

Can use the case command to set many different drive letter mapping for different groups all within one file.

<vb> On Error Resume next Dim WshNetwork

Set WshNetwork = WScript.CreateObject("WScript.Network") Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName Set objUser = GetObject(strUserPath)

WshNetwork.RemoveNetworkDrive "H:" WshNetwork.RemoveNetworkDrive "I:" WshNetwork.RemoveNetworkDrive "J:" WshNetwork.RemoveNetworkDrive "K:" WshNetwork.RemoveNetworkDrive "L:" WshNetwork.RemoveNetworkDrive "M:" WshNetwork.RemoveNetworkDrive "O:" WshNetwork.RemoveNetworkDrive "P:" WshNetwork.RemoveNetworkDrive "Q:" WshNetwork.RemoveNetworkDrive "R:" WshNetwork.RemoveNetworkDrive "S:" WshNetwork.RemoveNetworkDrive "T:" WshNetwork.RemoveNetworkDrive "U:" WshNetwork.RemoveNetworkDrive "V:" WshNetwork.RemoveNetworkDrive "W:" WshNetwork.RemoveNetworkDrive "X:" WshNetwork.RemoveNetworkDrive "Y:" WshNetwork.RemoveNetworkDrive "Z:"

For Each strGroup in objUser.MemberOf

strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case strGroupName


Case "AD GROUP NAME1"
	objNetwork.MapNetworkDrive "S:", "\\server\share$"
Case "AD GROUP NAME2"
	objNetwork.MapNetworkDrive "T:", "\\server\share$"
End Select

Next

</vb>