Answered by:
Copy Group Membership From One Group to Another

Question
-
I have tried to copy users from one security group to another but getting error Object no found in line 11. Does anyone has idea regarding error?
VBScriptstrSGroupDN = InputBox ("Enter the DN of Source Group" & VBCRLF &_ vbcrlf& _ vbcrlf& _ "e.g. CN=Source Group,OU=Users,DC=NWTraders,DC=com") strDGroupDN = InputBox ("Enter the DN of Destination Group" & VBCRLF &_ vbcrlf& _ vbcrlf& _ "e.g. CN=Destination Group,OU=Users,DC=NWTraders,DC=com") set dicSeenGroupMember = CreateObject("Scripting.Dictionary") set objDGroup = GetObject("LDAP://" & strDGroupDN) DisplayMembers "LDAP://" & strSGroupDN, dicSeenGroupMember Function DisplayMembers (strGroupADsPath, dicSeenGroupMember) set objGroup = GetObject(strGroupADsPath) for each objMember In objGroup.Members objDGroup.Add("LDAP://" & objMember.distinguishedName) next End Function MsgBox "Group Members have been copied to Destination Group"
Thanks,
KiritFriday, February 5, 2010 4:03 PM
Answers
-
- Marked as answer by IamMred Friday, February 5, 2010 10:37 PM
Friday, February 5, 2010 4:13 PM -
You don't say which is line 11, but my guess is:
set objDGroup = GetObject("LDAP://" & strDGroupDN)
in which case the error means the the distinguished name value supplied by the user was incorrect (or the user is not authenticated to the domain). The script itself is fine, although the dictionary object is never used. Also, an error would be raised if any members of the source group are already members of the destination group. I would revise the script as follows:strSGroupDN = InputBox ("Enter the DN of Source Group" & VBCRLF &_ vbcrlf& _ vbcrlf& _ "e.g. CN=Source Group,OU=Users,DC=NWTraders,DC=com") strDGroupDN = InputBox ("Enter the DN of Destination Group" & VBCRLF &_ vbcrlf& _ vbcrlf& _ "e.g. CN=Destination Group,OU=Users,DC=NWTraders,DC=com") ' Bind to source group. Set objSGroup = GetObject("LDAP://" & strSGroupDN) ' Bind to destination group. Set objDGroup = GetObject("LDAP://" & strDGroupDN) ' Enumerate members of source group. For Each objMember In objSGroup.Members ' Check if member of destination group. If (objDGroup.IsMember(objMember.ADsPath) = False) Then ' Add member to destination group. objDGroup.Add(objMember.ADsPath) End If Next
But this does not address your error, which must be due to an incorrect Distinguished Name.
Richard Mueller
MVP ADSI- Marked as answer by IamMred Friday, February 5, 2010 10:37 PM
Friday, February 5, 2010 5:32 PM
All replies
-
- Marked as answer by IamMred Friday, February 5, 2010 10:37 PM
Friday, February 5, 2010 4:13 PM -
Hi Assaf,
Thanks for quick respond, I am new bee for scripting, I got a below error while executing script, please suggest.
Script: C:\copyuserBetweenGroups.vbs
Line: 73
Char: 1
Error: Invalid Syntax
Code: 800401E4
Source: (Null)
ThanksFriday, February 5, 2010 4:47 PM -
You don't say which is line 11, but my guess is:
set objDGroup = GetObject("LDAP://" & strDGroupDN)
in which case the error means the the distinguished name value supplied by the user was incorrect (or the user is not authenticated to the domain). The script itself is fine, although the dictionary object is never used. Also, an error would be raised if any members of the source group are already members of the destination group. I would revise the script as follows:strSGroupDN = InputBox ("Enter the DN of Source Group" & VBCRLF &_ vbcrlf& _ vbcrlf& _ "e.g. CN=Source Group,OU=Users,DC=NWTraders,DC=com") strDGroupDN = InputBox ("Enter the DN of Destination Group" & VBCRLF &_ vbcrlf& _ vbcrlf& _ "e.g. CN=Destination Group,OU=Users,DC=NWTraders,DC=com") ' Bind to source group. Set objSGroup = GetObject("LDAP://" & strSGroupDN) ' Bind to destination group. Set objDGroup = GetObject("LDAP://" & strDGroupDN) ' Enumerate members of source group. For Each objMember In objSGroup.Members ' Check if member of destination group. If (objDGroup.IsMember(objMember.ADsPath) = False) Then ' Add member to destination group. objDGroup.Add(objMember.ADsPath) End If Next
But this does not address your error, which must be due to an incorrect Distinguished Name.
Richard Mueller
MVP ADSI- Marked as answer by IamMred Friday, February 5, 2010 10:37 PM
Friday, February 5, 2010 5:32 PM -
Hey thanks... it worked. THanks for your helpFriday, February 5, 2010 6:25 PM