+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Mapping network drives based upon user group. in Coding and Web Development; Hi Please can someone tell me how to map a network drive based upon a users group and how to ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427

    Mapping network drives based upon user group.

    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

  2. #2

    Join Date
    Apr 2006
    Location
    West Midlands
    Posts
    314
    Thank Post
    29
    Thanked 19 Times in 18 Posts
    Rep Power
    20
    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
    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.
    Last edited by kiran; 25th February 2008 at 09:20 PM.

  3. #3
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    33
    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.

  4. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,392
    Thank Post
    797
    Thanked 1,588 Times in 1,391 Posts
    Blog Entries
    10
    Rep Power
    427
    Thats what i thought originally but i don't want to alter the OU structure

  5. #5
    Hedghog's Avatar
    Join Date
    Jul 2006
    Location
    North Wales
    Posts
    194
    Thank Post
    35
    Thanked 17 Times in 16 Posts
    Rep Power
    36
    Another method would be to have a different logon script for each group (if you use them) to set the required drives.

    Peter

  6. #6
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    33
    Quote Originally Posted by Hedghog View Post
    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.

  7. #7
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    33
    Quote Originally Posted by FN-Greatermanchester View Post
    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.

  8. #8
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    33
    Oh - forgot to mention how to rename drives

    sDriveLetter = "G:\"
    Set oShell = CreateObject("Shell.Application")
    oShell.NameSpace(sDriveLetter).Self.Name = "Group Work Area"

  9. #9

    Join Date
    May 2008
    Posts
    9
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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

SHARE:
+ Post New Thread

Similar Threads

  1. mapping drives
    By rjsmith in forum *nix
    Replies: 2
    Last Post: 14th November 2007, 05:42 PM
  2. mapping drives
    By chrbb in forum Wireless Networks
    Replies: 3
    Last Post: 3rd November 2007, 03:18 PM
  3. Mapping Printers based on Location
    By NeoNemesis in forum Windows
    Replies: 11
    Last Post: 6th August 2007, 08:03 AM
  4. Mapping Network Drives ?
    By mac_shinobi in forum Scripts
    Replies: 9
    Last Post: 8th March 2007, 03:49 PM
  5. ISA 2004 - Upstream proxy based on user group?
    By Ravening_Wolf in forum Wireless Networks
    Replies: 0
    Last Post: 11th December 2006, 01:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •