Jump to content

Mapping network drives based upon user group.


Recommended Posts

Posted (edited)


'CONSTRUCTORS
'----------------------------------------------
Option Explicit

Dim objNetwork, objSysInfo, strUserDN
Dim objGroupList, objUser, objFSO
Dim strComputerDN, objComputer
Dim WshNetwork
Dim UserName
Dim ComputerName


set Wshnetwork = CreateObject("WScript.Network")

Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSysInfo = CreateObject("ADSystemInfo")

strUserDN = objSysInfo.userName
strComputerDN = objSysInfo.computerName

Set WshNetwork = WScript.CreateObject("WScript.Network")

' USERNAME & COMPUTER VARIABLES CONSTRUCTOR
' -----------------------------------------------------
' Save the username and computer name in variables
' ComputerName is converted to LOWERCASE to ensure proper matching later
' on.
UserName = WshNetwork.UserName
ComputerName = lcase(WshNetwork.ComputerName)

' pop a dialog box up on the client as you login that displays the computer name and users name
'WScript.Echo "You are logged into Computer = " & ComputerName & Chr(13) & " As Username = "& UserName

' Bind to the user and computer objects with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)
Set objComputer = GetObject("LDAP://" & strComputerDN)



' NETWORK DRIVE ASSIGNMENTS
' -----------------------------------------------------------------
' Map a network drive if the user is a member of the group.
' Alert the user if the drive cannot be mapped.

WshNetwork.MapNetworkDrive "H:", "\\Servername\Users\"& UserName
WshNetwork.MapNetworkDrive "T:", "\\Servername\ClientApps"



If IsMember(objUser, "GroupName") Then

If Not MapDrive("P:", "\\Servername\Profiles") Then
MsgBox "Unable to Map P:\ to Profiles - Please contact ICT Services"
End If
End If

 

First maps drives H:\ and T:\ - FOR ALL USERS then maps drives according to group membership.

 

May be little over complicated but my script then goes onto set default printers, more mappings by group.

Edited by kxv2020
Posted

The other way of doing this without all the code (and I'm certainly not saying this is a better way. It's just an alternative), is as follows;

 

1 - Create a dedicated policy to map the drive for the particular group

2 - In the policy, create a simple script to map the drive

3 - Assign the policy to the required OU and then modify the default filtering by removing Authenticated Users and adding in the group that you want to have the drive

 

One advantage of this method is that if the group is renamed, the drives will still be mapped, whereas with the long script, it will fail.

 

As I said, not a better solution, just an alternative.

Posted
Another method would be to have a different logon script for each group (if you use them) to set the required drives.

 

Peter

 

That's basically what I meant. Logon scripts (apart from the old fashioned ones linked directly to user accounts) are assigned via Group Policy and hence the requirement to have a policy for each logon script/group combination.

Posted
Thats what i thought originally but i don't want to alter the OU structure

 

No need to alter OU structure unless some/all your user accounts are in the 'Users' container.

 

Assuming you set it up like I suggested then you would simply assign the policies it the highest level OU to ensure all potential users are covered. The security filtering would then ensure the scripts execute (and hence drives map) for only those groups that have access to apply the policy.

Posted

Oh - forgot to mention how to rename drives

 

sDriveLetter = "G:\"

Set oShell = CreateObject("Shell.Application")

oShell.NameSpace(sDriveLetter).Self.Name = "Group Work Area"

  • 2 months later...
Posted

This is what i've been using. I used to have a script for each group. That was a pain. Now i only have to edit one script to make changes.

 

On Error Resume Next 
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Map network share by group
arrGroups = objUser.GetEx("memberOf")
  For Each strGroup in arrGroups
       Set objGroup = GetObject("LDAP://" & strGroup)
       strGroupName = objGroup.CN

       Select Case strGroupName

       Case "Students"
           objNetwork.MapNetworkDrive "X:", "\\fileserver\students$"

       Case "Teachers"
           objNetwork.MapNetworkDrive "K:", "\\fileserver\teachers$"

       End Select
Next

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...