D
Thu Jul 13 16:50:09 CDT 2006
Mahir,
You have to be careful with ".MemberOf" - I mean, if a user is a member of
only one group then ".MemberOf" is actually a "string" datatype. It is only
a "collection" datatype if the user is a member of two or more groups, and
it is "empty" if there are no groups. The code below illustrates what I
mean, and you'll have to tweak it to suit your needs.
Regards,
Dave.
Sub s_load_groups_ad( po_ad_object )
Const cs_fac = "%s_load_groups_ad, "
Dim lc_ls_groups, lo_group, ll_j
lc_ls_groups = po_ad_object.MemberOf 'Could be a collection, could be a
string.
If IsEmpty( lc_ls_groups ) Then Exit Sub
If TypeName( lc_ls_groups ) = "String" Then
set lo_group = GetObject( "LDAP://" & lc_ls_groups )
If Not gd_groups.Exists( lo_group.sAMAccountName ) Then
gd_groups( lo_group.sAMAccountName ) = "LDAP://"
Call s_load_groups_ad( lo_group )
End If
Set lo_group = Nothing
Exit Sub
End If
For ll_j = 0 To UBound( lc_ls_groups )
Set lo_group = GetObject( "LDAP://" & lc_ls_groups(ll_j) )
If Not gd_groups.Exists( lo_group.sAMAccountName ) Then
gd_groups( lo_group.sAMAccountName ) = "LDAP://"
Call s_load_groups_ad( lo_group )
End If
Next
Set lo_group = Nothing
End Sub
"Mahir Jamakovic" <MahirJamakovic@discussions.microsoft.com> wrote in
message news:7159D753-F967-4C41-8CFC-5AC361BF08A6@microsoft.com...
> Thank you very much this will work for me
>
> "Richard Mueller" wrote:
>
>> Mahir Jamakovic wrote:
>>
>> > I'm trying to modify this script so instead mapping network drives
>> > based
>> > on
>> > group membership to map network drive based on user login name.
>> >
>> > *********************************************************
>> > 'VBS script, Map Drives Based on Group Membership
>> >
>> > 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 "IS Staff"
>> > objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
>> > objNetwork.MapNetworkDrive "W:", "\\Server2\Internal"
>> >
>> > Case "Network Staff"
>> > objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
>> >
>> > Case "Domain Admins"
>> > objNetwork.MapNetworkDrive "Y:", "\\DFS_Root\Shared"
>> >
>> > Case "PSR Users"
>> > objNetwork.MapNetworkDrive "Z:", "\\DFS_Root\Irwindale"
>> > End Select
>> > Next
>> > ************************************************************
>>
>> If you want the Distinguished Name of the user, you can use
>> objSysInfo.UserName, and create a "Select Case" with that. It might make
>> more sense to retrieve the NT Name (the "pre-Windows 2000 logon name")
>> from
>> the wshNetwork object. For example:
>>
>> Set objNetwork = CreateObject("Wscript.Network")
>> strName = objNetwork.UserName
>> Select Case LCase(strName)
>> Case "jimsmith"
>> objNetwork.MapNetworkDrive "V:", "\\Server1\C$"
>> Case "lwilson"
>> objNetwork.MapNetworkDrive "X:", "\\Server2\HQ"
>> End Select
>>
>> I made the comparisons case insensitive with the LCase function, and used
>> all lower case logon names. This would only be feasible with a small
>> group
>> of users.
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab -
http://www.rlmueller.net
>>
>>
>>