Add Global Group to Domain Local Group with VBS

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 12 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mmacdonald
Posts: 44
Last visit: Thu Apr 07, 2016 7:53 am

Add Global Group to Domain Local Group with VBS

Post by mmacdonald »

Hello: This is a very remedial question that seems to be stumping me.I want to add a Global Group to a Domain Local Group.I 'wrote' (read as hobbeled together) the script that creates the two groups. I then want to add one to the other. I have seen several examples but nothing seems to work.I am reading the list of groups from a csv. Here's the basic code I am using:Do Until oRecordSet.EOF ' Reads the values (cells) in the sInputFile file. sSAMAccount = oRecordSet.Fields.Item(0).Value sDescription = oRecordSet.Fields.Item(1).Value sInfo = oRecordSet.Fields.Item(2).Value sManager = oRecordSet.Fields.Item(3).Value sGType = oRecordSet.Fields.Item(4).Value sMemberOf = oRecordSet.Fields.Item(5).Value Set oNewGroup = oContainer.Create("Group","cn=" & sSAMAccount) oNewGroup.put "sAMAccountName",sSAMAccount oNewGroup.put "description",sDescription oNewGroup.put "info",sInfo oNewGroup.put "managedBy",sManager oNewGroup.put "groupType",sGType or _ ADS_GROUP_TYPE_SECURITY_ENABLED oNewGroup.add(sMemberOf.ADSPath) oNewGroup.SetInfo
oRecordSet.MoveNext()LoopI have tried many variations at the oNewGroup.add(sMemberOf.ADSPath) line to no avail. Anyone who may have a suggestion is welcome to comment.Thank you.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Add Global Group to Domain Local Group with VBS

Post by jvierra »

You have to 'Get' the group and add it as an object. WInNT will do the rest.

I am still trying to figure out why you have so much code to add a group when you only need the local group and the domain group. What is all of the recordset stuff?

Set grp = GetObject{"WInNT://computer/group"}
Set domgrp = GetObject)"LDAP://......)
grp.Add domgrp.aDSPath

That is all you have to do as best I can remember.

jvierra2011-09-30 16:25:49
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Add Global Group to Domain Local Group with VBS

Post by jvierra »

Why didn't you jsut ask about how to create a domain group and add a group to it.

!. What OU do you want to create it in.
2. Create the group on the OU (container). [ like you wer4e doing ]
3.add one to the other .

No need for a recordset.

Set ou - GetObject ( adspath to OU)
set grp = ou.Create( "Group", "cn=mygroup")
Set grp2 = GetObject("adsPath to group")
grp2.Add grp.Adspath

None of this should require all of the property type stuff. Add does not require 'setinfo' All methods on objects are self commiting. Only properties need to be committed. ( don't ask me why - that is just how Microsoft built
it)


This topic is 12 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked