Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following problem:

When i run my LOGON_SCRIPT.vbs to add network shares to users of a specific group it skips the first one if the user is part of Kleinkunstig_Users (it will not add the first share). But if i add another group it will add the share of the first one and the other. Please help? (script is below)

'start script

On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

'find user name

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

'find user group's

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

' if user member of a group then map network drive

Select Case strGroupName
Case "Kleinkunstig_Users"
objNetwork.MapNetworkDrive "Y:", "\\KL01\Kleinkunstig"

Case "Kleinkunstig_Sales" 
objNetwork.MapNetworkDrive "V:", "\\KL01\Sales"

Case "Kleinkunstig_Marketing" 
objNetwork.MapNetworkDrive "M:", "\\KL01\Marketing"

Case "Kleinkunstig_Maanagement" 
objNetwork.MapNetworkDrive "X:", "\\KL01\Management"

Case "Kleinkunstig_IT" 
objNetwork.MapNetworkDrive "I:", "\\KL01\IT"

Case "Kleinkunstig_Financial" 
objNetwork.MapNetworkDrive "O:", "\\KL01\Financial"

Case "Kleinkunstig_Administrator" 
objNetwork.MapNetworkDrive "Q:", "\\KL01\Administrators"
End Select

'end script
share|improve this question

In the following code, MemberOf may return either a collection or a string value (if the user is a member of only one group in addition to their primary group):

For Each strGroup in objUser.MemberOf

You can't "For Each" over objUser.MemberOf if objUser.MemberOf is a string.

There is probably an error which you are not seeing due to the following line:

On Error Resume Next

(note that removing that line from a script that many users are executing could mean that they all start receiving errors on login)

One very dirty way of testing and fixing this is to add the users in question to a "dummy" additional group. This should force the value returned by MemberOf to be a collection that you can then enumerate with For Each.

I have had success with a script similar to the one in this answer: Automatically run a script when I log on to Windows, quoted here:

Const ENGINEERING_GROUP     = "cn=engineering"
Const FINANCE_GROUP         = "cn=finance"
Const HUMAN_RESOURCES_GROUP = "cn=human resources"

Set wshNetwork = CreateObject("WScript.Network")
wshNetwork.MapNetworkDrive "h:",
"\\FileServer\Users\" & wshNetwork.UserName

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" &
strGroups = LCase(Join(CurrentUser.MemberOf))

If InStr(strGroups, ENGINEERING_GROUP) Then

    wshNetwork.MapNetworkDrive "g:",

ElseIf InStr(strGroups, FINANCE_GROUP) Then

    wshNetwork.MapNetworkDrive "g:",

ElseIf InStr(strGroups, HUMAN_RESOURCES_GROUP) Then

    wshNetwork.MapNetworkDrive "g:",
    "\\FileServer\Human Resources\"

End If

In theory, the above approach could cause issues if one of your group names is a substring of another, such as "finance" and "finance and auditing".

There are any number of other possible approaches, including testing the value returned by MemberOf to determine if it is a string or an array.

Possible alternative to using a login script to map network drives (may require more recent server / client versions than you currently have):

Best of luck!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.