Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Map drives based on (domain) group membership

Posted on 2006-04-07
Medium Priority
Last Modified: 2010-03-19
WHat I want to do is have one script run at login for all users which will query AD for group membership and map the correct drives for each group.
user logs in
script gets all users group membership
Say user is a member of domain users, gp1, and gp2,
Script runs logon part
If member gp1           ///maps this
 map \\server\share
If member gp99      ///dosent map this
 map \\server\share

Ive tried using the Ifmember exe on the 2000 res kit but it dosent seem to work half the time.
A possibility is the script below but I cant get it to work properly. It will get the local username and echo this back (for testing) this part works. If you look at the strUser ="cn=administrator," you will note I need to change this to the variable USERNAME which dosent seem to work for me because even if I change strUser ="cn=administrator," to for example strUser ="cn=admin," the script errors out.

Can anyone fix my script or suggest a better way?

' UsermemberOf Adv.vbs
' To list the groups to which the administrator is a memberOf
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.3 - May 2005
' ---------------------------------------------------------------'
Option Explicit
Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf
Dim strOU, strUser, strDNSDomain, strLDAP, strList, USERNAME
Dim arrGroup
Dim objShell, WshShell, WshSysEnv, ComputerName, out, FSO, filesys, filetxt, Date
Dim strDriveLetter1, strNewName1, strDriveLetter2, strNewName2
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
Set fso = CreateObject("Scripting.FileSystemObject")

WScript.Echo "Username is " & USERNAME

' Commands to bind to AD and extract domain name
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")

' Build the LDAP DN from strUser, strOU and strDNSDomain
strList ="-------------------------------" & vbCr
strUser ="cn=administrator,"
strOU ="CN=Users,"
strLDAP ="LDAP://" & strUser & strOU & strDNSDomain
Set objUser = GetObject(strLDAP)

' Heart of the script, extract a list of Groups from memberOf
objmemberOf  = objUser.GetEx("memberOf")
For Each objGroup in objmemberOf
   objGroup = Mid(objGroup, 4, 330)
   arrGroup = Split(objGroup, "," )
   strList = strList & arrGroup(0) & vbcr

' Additional section to find the primary group.
If objUser.primaryGroupID = 513 Then
   strList = strList & vbCr & "Primary Group: " _
   & vbCr & "Domain Users" & vbCr
Else If objUser.primaryGroupID = 515 Then
   strList = strList & "Domain Computers"
Else strList = strList & "Maybe a Domain Controller"
End If
End If
WScript.Echo "Groups for " & Mid(strUser, 4, 99) & vbCr & strList


' End of Sample User memberOf  and primaryGroupID VBScript
Question by:lucid911

Accepted Solution

salvagbf earned 1000 total points
ID: 16401412
I use Kixtart to accomplish this.


The actual code in your kixtart script would just be

if INGROUP("domainName\groupName")
      use x: "\\serverName\share1a"
      use y: "\\serverName\share2$"

Author Comment

ID: 16415655
Absolutely perfect. I cant thank you enough! I spend a week trying to get Vbscript to do what you showed me how to do in five mins.
Thanks again

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question