Hi
Please can someone tell me how to map a network drive based upon a users group and how to rename the drive please?
Thanks

Hi
Please can someone tell me how to map a network drive based upon a users group and how to rename the drive please?
Thanks
First maps drives H:\ and T:\ - FOR ALL USERS then maps drives according to group membership.Code:'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
May be little over complicated but my script then goes onto set default printers, more mappings by group.
Last edited by kiran; 25th February 2008 at 10:20 PM.
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.

Thats what i thought originally but i don't want to alter the OU structure
Another method would be to have a different logon script for each group (if you use them) to set the required drives.
Peter
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.
Oh - forgot to mention how to rename drives
sDriveLetter = "G:\"
Set oShell = CreateObject("Shell.Application")
oShell.NameSpace(sDriveLetter).Self.Name = "Group Work Area"
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.
Code: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
There are currently 1 users browsing this thread. (0 members and 1 guests)