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

x
?
Solved

Map drives based on (domain) group membership

Posted on 2006-04-07
2
Medium Priority
?
330 Views
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.
IE
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
:next
If member gp99      ///dosent map this
 map \\server\share
:next

etc
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")

USERNAME = WshSysEnv.Item("USERNAME")
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
Next

' 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

WSCript.Quit

' End of Sample User memberOf  and primaryGroupID VBScript
0
Comment
Question by:lucid911
2 Comments
 
LVL 6

Accepted Solution

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

http://www.kixtart.org

The actual code in your kixtart script would just be

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

Author Comment

by:lucid911
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
0

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