Re: script error
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Sep 2007 21:17:47 -0500
glnntc wrote:
when i try running this i get an error "wrong number of arguments or
invalid property assignment" for the line ised the for-next cycle.
This script is supposed to enumerate members of groupA and add them to
group B (both groups already exist)
I can't see what's wrong with the code
---------------------------------------------------------------------------
'Add Users from Group A to Group B
Set objOldGroup = GetObject("LDAP://CN=GroupA,ou=sales,dc=dom,dc=local")
Set objNewGroup = GetObject("LDAP://CN=GroupB,ou=sales,dc=dom,dc=local")
For Each objUser in objOldGroup.Members
objNewGroup.Add "LDAP://" & objUser
Next
----------------------------------------------------------------------------
The Add method of the group object takes the AdsPath of the new member as an
argument. You could either pass objUser.AdsPath or "LDAP://" &
objUser.distinguishedName. Actually, I would first check if the user is
already a member. I would use code similar to:
==========
Set objOldGroup = GetObject("LDAP://CN=GroupA,ou=sales,dc=dom,dc=local")
Set objNewGroup = GetObject("LDAP://CN=GroupB,ou=sales,dc=dom,dc=local")
For Each objMember in objOldGroup.Members
If (objNewGroup.IsMember(objMember.AdsPath) = False) Then
objNewGroup.Add(objMember.AdsPath)
End If
Next
=========
I use objMember in place of objUser simply because members can be users,
computers, or groups.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--/
.
- References:
- script error
- From: glnntc
- script error
- Prev by Date: Re: VBScript - String - first letters to Uppercase
- Next by Date: Re: Changing Folder permission on remote computer using cacls
- Previous by thread: script error
- Next by thread: script error
- Index(es):
Relevant Pages
|