Creating groups in child OUs

Discussion in 'Scripting' started by Shashi, Jun 1, 2006.

  1. Shashi

    Shashi Guest

    Hallo,
    Here I am trying to crate a group in child ou but I get error"There is no
    such object on the server".
    Can anyone help me out.
    Set objOU =
    GetObject("LDAP://ou=R&D,ou=users,ou=Local,dc=NA,dc=fabrikam,dc=com")
    Set objGroup = objOU.Create("Group", "cn=Scientists")

    objGroup.Put "sAMAccountName", "scientists"
    objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP
    objGroup.SetInfo

    Thanks
    Shashi
     
    Shashi, Jun 1, 2006
    #1
    1. Advertisements

  2. users is not an ou but a cn :
    should look like this
    LDAP://ou=R&D,cn=users,ou=Local,dc=NA,dc=fabrikam,dc=com
     
    Daniel Giraud, Jun 1, 2006
    #2
    1. Advertisements

  3. Hi,

    As noted, the Distinguished Name of the OU the group will be created in is
    probably wrong. If your domain is called MyDomain.com, and you have an OU
    called R&D in the root of the domain, you can use:

    Set objOU = GetObject("LDAP://ou=R&D,dc=MyDomain,dc=com")

    If ou=R&D is in another ou called Local (so R&D is a child of Local), then:

    Set objOU = GetObject("LDAP://ou=R&D,ou=Local,dc=MyDomain,dc=com")

    I doubt there is a container involved. Also, in VBScript you must define the
    constant ADS_GROUP_TYPE_GLOBAL_GROUP. I use the following (watch line
    wrapping):

    Const ADS_GROUP_TYPE_GLOBAL_GROUP = &H2
    Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000

    objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or
    ADS_GROUP_TYPE_SECURITY_ENABLED

    If you only use ADS_GROUP_TYPE_GLOBAL you will create a distribution group.
    You must Or both constants to get a security group. See this link for
    explanation and good examples.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/ads_group_type_enum.asp
     
    Richard Mueller, Jun 1, 2006
    #3
  4. Shashi

    Shashi Guest

    Hi Richard and Daniel,

    I get error on line 9 any idea!!

    Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
    Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000

    Set objOU = GetObject("LDAP://ou=Groups,ou=R&D,dc=mydomain,dc=com")
    Set objGroup = objOU.Create("Group", "cn=Scientists")

    objGroup.Put "sAMAccountName", "scientists"
    objGroup.Put "groupType", ADS_GROUP_TYPE_SECURITY_ENABLED
    objGroup.SetInfo

    Whole idea is to create a global mail enabled group.
    Secondly is it possible to create more than one group in same ou. lastlty
    can be groub mail enable?

    thank you both , hope to hear soon.
    Shashi
     
    Shashi, Jun 1, 2006
    #4
  5. Hi,

    I assume line 9 is where SetInfo if invoked. I believe the problem is the
    value you assigned to groupType. A group cannot be just a security group, it
    must be both global and security. You need to "Or" the two bit masks as
    follows (watch line wrapping, the following is one statement):

    objGroup.Put "groupType", ADS_GROUP_TYPE_SECURITY_ENABLED Or
    ADS_GROUP_TYPE_GLOBAL_GROUP
     
    Richard Mueller, Jun 1, 2006
    #5
  6. Shashi

    Shashi Guest

    Hi Richard,

    It worked great, thanks a lot.
    To create many global security groups do I need to repeat these line in the
    script with new name or is there another command to add multiple name:

    Set objGroup = objOU.Create("Group", "cn=Scientists")

    objGroup.Put "sAMAccountName", "scientists"
    objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP or
    ADS_GROUP_TYPE_SECURITY_ENABLED

    I should eagerly wait for your reply.

    Thank you very much.


    thank you very much
    Shashi
     
    Shashi, Jun 6, 2006
    #6
  7. Shashi

    Eng Guest

    Use this:

    This script is composed by 3 file

    1 input.txt the input file is used to retrieve the object name
    2 the batch used to "run" the vbs and take the information from the txt
    3 the VBS file NewGroups.vbs

    The file BAT create a series of groups from
    the file input.txt. (use " " for the name of the groups)

    The groups will be created BY DEFAULT into OU=GROUPS
    if you specify inside the .vbs file the path where you
    want to create groups it will works for every OU.

    '****************************************************************************
    '* THe sintax you have to use to run the script is
    '* cscript newgroups.vbs NAME_OF_THE_GROUPS
    '* Name_of_the_groups rappresent the groups you need to create
    '*****************************************************************************


    '*****************************************************************************
    '* INTO STRVARIABL LINE PUT THE PATH WHERE THE GROUPS
    '* WILL CREATED (EX: strVariabl = ",OU=Standard Users,OU=DomainNAME,")
    '*****************************************************************************
    '*****************************************************************************
    strVariabl = "OU=groups"
    '*****************************************************************************
    '*****************************************************************************
    '*****************************************************************************

    That's all.

    Script by: Eugenio Talarico
    mailto: eugeniot @ _R_E_M_O_V_E___ larico.it

    so here the structure:

    1 input.txt

    GROUPS_NAME;Comment

    2 BATCH FILE

    @echo on

    echo ****************************************
    Echo * script for multiple groups creation *
    echo ****************************************


    for /F "tokens=1-2 usebackq delims=;" %%1 in (input.txt) do (
    cscript NewGroups.vbs %%1 %%2 //B //Nologo >> err_log.txt 2>>&1 )

    3 VBS FILE NewGroups.vbs

    '****************************************************************************
    '*
    '* Create a new groups IN an ACtive Directory Infrastructure
    '*
    '* Created By Eugenio Talarico - 10/12/2003
    '*
    '****************************************************************************
    '* THe sintax you have to use to run the script is
    '* cscript newgroups.vbs NAME_OF_THE_GROUPS
    '* Name_of_the_groups rappresent the groups you need to create
    '*****************************************************************************
    '*****************************************************************************
    '* INTO STRVARIABL LINE PUT THE PATH WHERE THE GROUPS
    '* WILL CREATED (EX: strVariabl = ",OU=Standard Users,OU=DomainNAME,")
    '*****************************************************************************
    '*****************************************************************************
    strVariabl = "OU=groups"
    '*****************************************************************************
    '*****************************************************************************
    '*****************************************************************************
    '**Start Encode**

    dim nome
    dim Commento
    ParseCommandLine()
    wscript.echo nome


    Const ADS_PROPERTY_APPEND = 3
    Set objRootDSE = GetObject("LDAP://rootDSE")

    strFissa = strVariabl & "," & objRootDSE.Get("defaultNamingContext")
    wscript.echo strFissa

    Set objGroup = GetObject _
    ("LDAP://"& strFissa)

    Set objGroup = objGroup.Create ("group", "CN=" & nome)
    objGroup.Put "sAMAccountName", nome
    ObjGroup.Put "Description", commento
    objGroup.SetInfo

    Sub ParseCommandLine()
    Dim vArgs

    set vArgs = WScript.Arguments

    if vArgs.Count <> 2 then
    DisplayUsage()
    Else
    nome = vArgs(0)
    commento = vArgs(1)
    End if
    End Sub
     
    Eng, Aug 21, 2006
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.