Home » Scripting » User creation script - Adding to groups Messages in this topic - RSS
|
12/30/2011 4:52:55 AM
ADixon
ADixon
Posts 2
I've written a script for AD user creation and am having issues when adding to security groups. Here is a snippet:

Function SetSecGroups()
Dim objOption
For Each objOption In SecGroups.Options
If objoption.selected then
GroupPath = objoption.value
UserPath = ("LDAP://" & strDistName)
addToGroup UserPath,GroupPath
Else
End If
Next
End function

Sub addToGroup(UserPath, GroupPath)
Dim objGroup
Set objGroup = GetObject(GroupPath)

For Each member In objGroup.members
If LCase(member.adspath) = LCase(userPath) Then
Exit Sub
End If
Next
objGroup.Add(UserPath)

End Sub

The whole script is a HTA which creates the user and set's all of the necessary attributes, this bit works fine but when trying to add to groups it fails. The groups are in a dropdown in the HTA so i use SecGroups.options to find the selected groups. The variables are passed to the addToGroup sub and it cycles through the existing members to ensure the new user isn't already a member. I use HTAEdit so can debug to an extent but i can't see why the new user isn't added. Can anyone shed any light on why this may be? Thanks in advance, AD
1/13/2012 1:39:49 PM
admin
admin
Posts 331
Hi,

What part of the script is failing and what error do you get? Have you checked the group path is the full ADsPath - not just the distinguished name? Does the bind to the group work and have you tried to bind to the userPath to ensure that is also correct. Here's a simpler example with less moving parts than your HTA if you want to try:

http://www.wisesoft.co.uk/scripts/vbscript_add_user_to_group.aspx

Hope this helps,

David
1/15/2012 1:18:00 PM
ADixon
ADixon
Posts 2
Thanks for the reply David.
This snippet works when used as a standalone vbs script to add a group to an existing user. I've found that (by using messageboxes) i am getting the correct ADS path. Also, adding a pause in the main HTA allows the user to be seen on the DC i use, otherwise it can't find the strDistName, even though i've used specific DC's for both adding the user and adding to groups. So the script is failing on the objGroup.Add right at the end.

Thanks for the example btw, i'll give that a go.

Many thanks for the help
pages: 1
|

Home » Scripting » User creation script - Adding to groups