Re: script error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
--/


.



Relevant Pages

  • Re: List Members of a Group (with user input)
    ... Wscript.Echo "No members" ... Dim objRootDSE, objTrans, strNetBIOSDomain, strGroup ... I would like one that does not require editing of the script each time. ... Dim UserCount, gga, CNgga ...
    (microsoft.public.scripting.vbscript)
  • Re: Finding users of a specific group and listing memberships of t
    ... report generated by the system that lists members of the Domain Admin group. ... Dim strGroupDN, objGroup, objMember, objMemberGroup, objFileSystem, ... >> Hi...I am trying to write a script that will list users of a specific ... >> Domain Admins group, I want it to list all those users group memberships. ...
    (microsoft.public.windows.server.scripting)
  • Re: I need help with a login script
    ... You rewrite the script but I think it will be time consuming trying ... "Costas" wrote: ... Users are members of security group Accounting sales etc. Lsnsrv01 is ... wshNetWork.SetDefaultPrinter "\\lsnsrv01\2840Color" ElseIf ...
    (microsoft.public.windows.server.sbs)
  • Re: I need help with a login script
    ... You rewrite the script but I think it will be time consuming trying ... On Error GoTo 0 ... Users are members of security group Accounting sales etc. Lsnsrv01 is the ... wshNetWork.SetDefaultPrinter "\\lsnsrv01\2840Color" ElseIf InStrThen ...
    (microsoft.public.windows.server.sbs)
  • Re: Missing Users in "Group Listing"...
    ... > script is listed below... ... > - Run the above script, and the user account in question will not be ... for all users that have a matching value for the "primaryGroupID" attribute ... Members method of the group object does include any members that have the ...
    (microsoft.public.scripting.vbscript)