Add User to group through comparison to other user's memberships




I have a "New User" script which is very complex and handles adding most
AD properties upon creation, address tab, phones, profile tab,
organisation tab, etc. It also will use any existing user as a template
for group membership addition. I was using the WinNT method in this
script, and am now changing that to the LDAP method since the WinNT
method doesn't pick up distribution groups. However, I am now getting a
"bad path" error when I try to add the groups to the new user. Can
someone assist me here please. I will paste the pertinent section in
here, as the original script is nearly 1000 lines of code

I have added a comment where the error is occurring

Here is the section of script that I am struggling with:



Function DuplicateUser()

strUsr2Duplicate = inputbox("What is the username you wish to duplicate
the membership of? " & vbCrLf & vbCrLf & "Enter the LOGIN ID of the
required user, using the First Initial + Lastname format as in the below
example:" & vbCrLf & vbCrLf & "Joe User would be" & vbCrLf & vbCrLf &
"juser" & vbCrLf, "Group Membership Duplication process")
strDomain = "MyDomain"

if strUsr2Duplicate = "" then
msgbox "No user requested - No group memberships will be duplicated"
else
call LocateUser
End if
End Function

Function LocateUser()
'On Error Resume Next
Set ObjUser1 = Getobject("WinNT://" & strDomain & "/" &
strUsr2Duplicate & ",user")
if err.number<>0 then
Call BadUserName
Else
Call DuplicateUserFinish
End if
End Function

Function BadUserName()
MsgBox "You've chosen a username which does not exist"
intAnswer = _
Msgbox("Do you wish to choose another username for Group
Membership duplication?", _
vbYesNo, "Copy User Membership?")
If intAnswer = vbYes Then
Call DuplicateUser
Else
Msgbox "No user requested - No group memberships will be
duplicated"
End if
End Function

Function DuplicateUserFinish()
' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Use the Set method to specify the NT format of the object name.
' Trap the error if the user does not exist.
'On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNTName
If (Err.Number <> 0) Then
Wscript.Echo "User " & strUsrName & " not found."
Wscript.Quit
End If
On Error GoTo 0
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Bind to the user object in Active Directory with the LDAP provider.
Set objUser2 = GetObject("LDAP://"; & strUserDN)
' Enumerate groups that first user belongs to.
For Each objGroup In objUser1.Groups
' Check if second user belongs.
If (objGroup.IsMember(objUser2.AdsPath) = False) Then
' Add the second user to the group.

' HERE IS WHERE I GET THE ERROR
objGroup.Add(objUser2.AdsPath)
End if
Next

Wscript.Echo "Success " & strUsr2Duplicate & "'s Group Memberships have
been duplicated for " & strSAm
End function


--
SecurityGuy
------------------------------------------------------------------------
SecurityGuy's Profile: http://forums.techarena.in/members/85156.htm
View this thread: http://forums.techarena.in/active-directory/1148717.htm

http://forums.techarena.in

.



Relevant Pages

  • Re: Seperating CSV rows into new, seperate files
    ... of a script but it still has one more problem. ... will import the list will ignore duplicate rows. ... >> and I am working on a way to parse a CSV file of class lists from MS ... The difference is that the session number changes. ...
    (comp.lang.python)
  • Re: Visual Studio SP6
    ... I was only looking for a manifest file in that mess, ... when I loaded it up and clicked on the Make tab in Project ... I can duplicate it just by opening the project, ... Post replies to the newsgroup. ...
    (microsoft.public.vb.general.discussion)
  • Re: Compare tables for duplicates
    ... There are regular fields that have a different value in each record, and global fields which have the same value in all the records of that file. ... If I create a regular field that I name 'Constant' of type 'Texte' and that I make 'Calculated', then I may say that that calculation will be 1 and type 'Number'. ... Say in A, I want to tell B of the value of the NameID of the current record of A. I then make a script line in A saying 'Set Field' where 'gn1' is a global field numeric, then a second script line passes the hand to B by 'Perform Script. ... I created a field in Table A called Duplicate. ...
    (comp.databases.filemaker)
  • Re: Compare tables for duplicates
    ... There are regular fields that have a different value in each record, and global fields which have the same value in all the records of that file. ... If I create a regular field that I name 'Constant' of type 'Texte' and that I make 'Calculated', then I may say that that calculation will be 1 and type 'Number'. ... Say in A, I want to tell B of the value of the NameID of the current record of A. I then make a script line in A saying 'Set Field' where 'gn1' is a global field numeric, then a second script line passes the hand to B by 'Perform Script. ... I created a field in Table A called Duplicate. ...
    (comp.databases.filemaker)
  • RE: HELP! Evil virus embedded in IE 7!!!
    ... Running Windows XP Service Pack 2. ... How to Troubleshoot Script Errors in Internet Explorer ... Error Message When You Browse the Web: An Error Has Occurred in the Script ... Click on General Tab and you will see a Button called ...
    (microsoft.public.windowsxp.general)

Quantcast