Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need script to check Group membership 1

Status
Not open for further replies.

larsjuhl

IS-IT--Management
Oct 24, 2001
88
DK
I need a login script that checks what groups the user is member of and then map the appropiate drives.
I have a Win2000 server and win2000 workstations running AD, I guess this script has been done before so I was hoping someone could supply with one or just help me in the right direction...! im a newbee to scripting.
thx in advance
Lars
 
Try this to get started, this lists all the groups that a user is a member of. You could easily take this and add your mapped drive logic in the for loop.

Hope this helps
TQ


Dim grp, Root, DomainPath, Domain, sOU, sUser
Set Root = GetObject("LDAP://RootDSE")
DomainPath = Root.Get("DefaultNamingContext")
Set Domain = GetObject("LDAP://" & DomainPath)


sOU = "OU Name"
sUser = "users name"

set objUser = GetObject("LDAP://CN=" & sUser & ",OU=" & sOU & "," & domainpath)

wscript.echo sUser & " is a member of the following groups"
for each objGroup in objUser.Groups
wscript.echo objGroup.Name & vbCRLF
next



set objuser = nothing
set Grp = nothing
set root = nothing
set domain = nothing
set obj = nothing
set oUser = nothing
 
thanks,
can you maybe guide me where I need to change the script so it fits my AD ?

Im having difficulties with the scripting part.. and just need this script to work then I clearly have to start reading books about it!!

 
I have now ended up using kix for this and that went smooth
 
I'm not the best vbscript writer and I know this could be cleaned up but it works for me. You need to grab IfMember from the MS website and put it on the user's drive or change the path of the exe.

Anyway, here you go:

' .......................................................
' Mapping network drive based on group membership
' .......................................................
Dim oNet, sUser, grp, ret
Set oNet = CreateObject("WScript.Network")
sUser = oNet.UserName
Set grp = GetObject("WinNT://Univertical/Clientele Group")
ret = grp.IsMember("WinNT://Univertical/" & sUser) ' Should be TRUE.
If ret=True Then
On Error Resume Next
Set Network = CreateObject("WScript.Network")
Drive = "Q:"
Share = "\\UNI02\Apps"
DGroup = "Clientele Group"
ELevel = Shell.Run("%SystemRoot%\SYSTEM32\Ifmember " & DGroup,0,True)
WScript.Echo " Mapping drive " & Drive & " to Clientele"
Network.MapNetworkDrive Drive, Share
If Err.Number = 0 Then
WScript.Echo " Map Successful "
Else
WScript.Echo " Error mapping drive " & Drive & " to Clientele"
End If
Else
WScript.Echo " " & sUser & " is not a member of Clientele Group"
End If
' ........................................................
 
This is right off MSDN if you would like to research it further. I modified it a little to work with vbscript.
You can look at the following links for more information:
ADSI WinNT Provider

ADSI Objects of WinNT

IADsUser

For example purposes the domain is Microsoft, the group is Administrators, and the user is jeffsmith

Dim grp, ret
On Error Resume Next

Set grp = GetObject("WinNT://Microsoft/Administrators")
ret = grp.IsMember("WinNT://Microsoft/jeffsmith") ' Should be TRUE.
If ret=True Then
wscript.echo "Is a Member"
Else
cleanup
End If

Function Cleanup
MsgBox("An error has occurred. " & ret)
Set grp = Nothing
End function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top