jamesjames1
Technical User
Hi,
I am trying to script a computer account move in AD which depends on the last logged on users group membership. I cant do this from a login script so need to do it from a domain controller.
I have got the code to get the users group membership and this populates an array. I am having difficulty searching through the array for the group name. Here is the code to get the group which the user is a member of:
strUserDN = "<UserDN>" cn=jsmith,cn=Users,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
set objUser = GetObject("LDAP://" & strUserDN)
Wscript.Echo "Group membership for " & objUser.Get("cn") & ":"
strSpaces = ""
set dicSeenGroup = CreateObject("Scripting.Dictionary")
DisplayGroups "LDAP://" & strUserDN, strSpaces, dicSeenGroup
Function DisplayGroups ( strObjectADsPath, strSpaces, dicSeenGroup)
set objObject = GetObject(strObjectADsPath)
WScript.Echo strSpaces & objObject.Name
on error resume next ' Doing this to avoid an error when memberOf is empty
if IsArray( objObject.Get("memberOf") ) then
colGroups = objObject.Get("memberOf")
else
colGroups = Array( objObject.Get("memberOf") )
end if
for each strGroupDN In colGroups
if Not dicSeenGroup.Exists(strGroupDN) then
dicSeenGroup.Add strGroupDN, 1
DisplayGroups "LDAP://" & strGroupDN, strSpaces & " ", dicSeenGroup
end if
next
End Function
I am reading the DN's from an excel spreadsheet so have added a loop which takes the name from the spreadsheet, populates the strUserDN variable then loops. I plan to write a select statement with the various group to call various sub routines to move the computer objects.
Any help would be good
I am trying to script a computer account move in AD which depends on the last logged on users group membership. I cant do this from a login script so need to do it from a domain controller.
I have got the code to get the users group membership and this populates an array. I am having difficulty searching through the array for the group name. Here is the code to get the group which the user is a member of:
strUserDN = "<UserDN>" cn=jsmith,cn=Users,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
set objUser = GetObject("LDAP://" & strUserDN)
Wscript.Echo "Group membership for " & objUser.Get("cn") & ":"
strSpaces = ""
set dicSeenGroup = CreateObject("Scripting.Dictionary")
DisplayGroups "LDAP://" & strUserDN, strSpaces, dicSeenGroup
Function DisplayGroups ( strObjectADsPath, strSpaces, dicSeenGroup)
set objObject = GetObject(strObjectADsPath)
WScript.Echo strSpaces & objObject.Name
on error resume next ' Doing this to avoid an error when memberOf is empty
if IsArray( objObject.Get("memberOf") ) then
colGroups = objObject.Get("memberOf")
else
colGroups = Array( objObject.Get("memberOf") )
end if
for each strGroupDN In colGroups
if Not dicSeenGroup.Exists(strGroupDN) then
dicSeenGroup.Add strGroupDN, 1
DisplayGroups "LDAP://" & strGroupDN, strSpaces & " ", dicSeenGroup
end if
next
End Function
I am reading the DN's from an excel spreadsheet so have added a loop which takes the name from the spreadsheet, populates the strUserDN variable then loops. I plan to write a select statement with the various group to call various sub routines to move the computer objects.
Any help would be good