Re: troubleshoot a script
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 16:16:37 -0500
Sorry, in glancing through the thread I missed that you posted your logon
script.
First, the batch file to launch the VBScript should only be needed if you
have Win9x clients. But, it's ok as long as drive Z: is always available.
Also, the recommended way to launch the VBScript is:
wscript %0\..\Logon.vbs
I see you use the memberOf attribute. Per this link:
http://www.rlmueller.net/MemberOf.htm
the statement:
For Each strGroup in objUser.MemberOf
will raise an error if memberOf has no DN's or one DN (Distinguished Name).
A solution could be:
=============
Option Explicit
Dim objSysInfo, objNetwork, strUserPath, objUser
Dim arrGroups, strGroupDN, objGroup
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
On Error Resume Next
arrGroups = objUser.GetEx("memberOf")
If (Err.Number <> 0) Then
On Error GoTo 0
' No group memberships except "primary".
Else
On Error GoTo 0
For Each strGroupDN In arrGroups
Set objGroup = GetObject("LDAP://" & strGroupDN)
Select Case LCase(objGroup.cn)
Case "stafffacultyadmin"
' map appropriate drives.
Case "library"
' map appropriate drives.
Case "quickbooks"
' map appropriate drives.
Case "teachers"
' map appropriate drives.
Case "volunteer"
' map appropriate drives.
End Select
Next
End If
========
I use the GetEx method to retrieve memberOf because it returns a variant
array that can be handled by the "For Each" structure even if there is only
one group. However, it raises an error if there are no groups, so I trap the
error. Also above I made the Select Case comparisons case-insensitive.
Since you are binding to the groups anyway, a better procedure would be to
use the IsMember method of the group objects. For example:
===============
Option Explicit
Dim objSysInfo, objNetwork, strUserPath, objUser
Dim objGroup
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
Set objGroup =
GetObject("LDAP://cn=StaffFacultyAdmin,ou=West,dc=MyDomain,dc=com")
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' map appropriate drives.
End If
Set objGroup = GetObject("LDAP://cn=Library,ou=West,dc=MyDomain,dc=com")
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' map appropriate drives.
End If
Set objGroup = GetObject("LDAP://cn=Quickbooks,ou=West,dc=MyDomain,dc=com")
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' map appropriate drives.
End If
Set objGroup = GetObject("LDAP://cn=Teachers,ou=West,dc=MyDomain,dc=com")
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' map appropriate drives.
End If
Set objGroup = GetObject("LDAP://cn=Volunteer,ou=West,dc=MyDomain,dc=com")
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' map appropriate drives.
End If
=========
You'll notice that I need to bind to the groups with the full Distinguished
Names (I made them up, substitute your own), but this method is more
reliable. In the previous code we check if the user is a member of any group
with the given Common Name. In truth, there could be several groups in the
domain with the same Common Name. In fact, this could be quite common in a
large enterprise network. The previous code would find a user a member of
"cn=Library,ou=West,dc=MyDomain,dc=com" even if they were really only
members of "cn=Library,ou=East,dc=MyDomain,dc=com". Using the full group DN
is the only way to be foolproof.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"Bret Snipes" <technokid@xxxxxxxxxxxxxxxx> wrote in message
news:ea6PDkm6HHA.4660@xxxxxxxxxxxxxxxxxxxxxxx
I run a batch file (this runs correctly) to delete mapped drives and map to
the users home folder. The part of the script that will not work for the 3
users is the section to map drives based on the "StaffFacultyAdmin" group.
Again it works for everyone but 3 users
THIS IS THE BATCH FILE THAT IS LAUNCED UNDER THE USERS PROFILE
net use * /delete /y
net use z: \\server\faculty_users$\%username%
cscript %logonserver%\NETLOGON\logon.vbs
THIS IS THE LOGONVBS FILE
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case strGroupName
Case "StaffFacultyAdmin"
objNetwork.MapNetworkDrive "R:", "\\server\Apps$"
objNetwork.MapNetworkDrive "Q:", "\\server\CommonFiles"
objNetwork.MapNetworkDrive "T:", "\\server\MULTIMEDIA"
objNetwork.MapNetworkDrive "x:", "\\server\Software"
Case "Library"
objNetwork.MapNetworkDrive "R:", \\server\mvcs_apps$\app
objNetwork.MapNetworkDrive "Q:", "\\server\Commonfiles"
Case "Quickbooks"
objNetwork.MapNetworkDrive "I:", "\\server\quickbooks$"
Case "Teachers"
objNetwork.MapNetworkDrive "S:", "\\server\Faculty_Grades$"
Case "Volunteer"
objNetwork.MapNetworkDrive "Q:", "\\server\Commonfiles"
objNetwork.MapNetworkDrive "T:", "\\server\MULTIMEDIA"
End Select
Next
Thanks for the help
Bret
"Pegasus (MVP)" <I.can@xxxxxxx> wrote in message
news:uGD6r0k6HHA.3400@xxxxxxxxxxxxxxxxxxxxxxx
"Bret Snipes" <technokid@xxxxxxxxxxxxxxxx> wrote in message
news:u9qdsfk6HHA.5096@xxxxxxxxxxxxxxxxxxxxxxx
I need to know how to troubleshoot a script. I have a script that maps
drives based on group membership. It runs for everyone but 3 users. I
don't get any messages - drives just don't map. How can I troubleshoot
where it is failing. Also I need to mention I did not write the script
but picked it up and have limited knowledge of scripting.
Thanks
Bret
Let's have a look at the script!
If you want to debug a logon script and if you don't
have an interactive script debugger then you might
be better off using a batch file instead. It shows you
each error as it occurs.
.
- References:
- troubleshoot a script
- From: Bret Snipes
- Re: troubleshoot a script
- From: Pegasus \(MVP\)
- Re: troubleshoot a script
- From: Bret Snipes
- troubleshoot a script
- Prev by Date: Re: How to call .dll functions ?
- Next by Date: Script retuning error on remote machine
- Previous by thread: Re: troubleshoot a script
- Next by thread: Re: troubleshoot a script
- Index(es):
Relevant Pages
|