Creating Global Groups from a text file

Home Forums Scripting General Scripting Creating Global Groups from a text file

This topic contains 5 replies, has 4 voices, and was last updated by Avatar bio 10 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #144234

    I have been at this for a couple of hours and just can’t figure what is going wrong.

    ‘==========================================================================
    ‘ AUTHOR: David R
    ‘ DATE : 9/2/2009
    ‘==========================================================================

    Const ForReading = 1

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objTextFile = objFSO.OpenTextFile _
    (“davidtestgrlst.txt”,ForReading)

    strText = objTextFile.ReadAll

    objTextFile.Close

    arrGroups = Split(strText, vbCrLf)

    Dim objAD, objGroup, objNewGroup, objUser, objRootDSE
    Dim objDomain, objOU
    Dim strGroup, strNewGroup, strPath, strUser
    Dim strOU, strDNSDomain
    Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
    Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

    Set objRootDSE = GetObject(“LDAP://RootDSE”)
    strDNSDomain = objRootDSE.Get(“DefaultNamingContext”)
    strOU =”OU=LDAPApplications,OU=Groups,”

    strPath =”LDAP://” & strOU & strDNSDomain
    Set objOU = GetObject(strPath)

    For Each strGroup in arrGroups

    On Error Resume Next

    Set objNewGroup = objOU.Create(“Group”, “cn=”& GroupName)
    objNewGroup.Put “sAMAccountName”, strGroup
    objNewGroup.Put “groupType”, ADS_GROUP_TYPE_GLOBAL_GROUP Or _
    ADS_GROUP_TYPE_SECURITY_ENABLED
    objNewGroup.SetInfo

    Next

    [/CODE]

    If anyone can point me to my error that would be great. The script runs but doesn’t create the group.

    Thanks,
    David[CODE]
    ‘==========================================================================
    ‘ AUTHOR: David R
    ‘ DATE : 9/2/2009
    ‘==========================================================================

    Const ForReading = 1

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objTextFile = objFSO.OpenTextFile _
    (“davidtestgrlst.txt”,ForReading)

    strText = objTextFile.ReadAll

    objTextFile.Close

    arrGroups = Split(strText, vbCrLf)

    Dim objAD, objGroup, objNewGroup, objUser, objRootDSE
    Dim objDomain, objOU
    Dim strGroup, strNewGroup, strPath, strUser
    Dim strOU, strDNSDomain
    Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
    Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

    Set objRootDSE = GetObject(“LDAP://RootDSE”)
    strDNSDomain = objRootDSE.Get(“DefaultNamingContext”)
    strOU =”OU=LDAPApplications,OU=Groups,”

    strPath =”LDAP://” & strOU & strDNSDomain
    Set objOU = GetObject(strPath)

    For Each strGroup in arrGroups

    On Error Resume Next

    Set objNewGroup = objOU.Create(“Group”, “cn=”& GroupName)
    objNewGroup.Put “sAMAccountName”, strGroup
    objNewGroup.Put “groupType”, ADS_GROUP_TYPE_GLOBAL_GROUP Or _
    ADS_GROUP_TYPE_SECURITY_ENABLED
    objNewGroup.SetInfo

    Next

    [/CODE]

    If anyone can point me to my error that would be great. The script runs but doesn’t create the group.

    Thanks,
    David

    #296825

    Re: Creating Global Groups from a text file

    ok so here is an update:

    I removed “On error resume next” and got this error Error: An invalid DN Syntax has been specified Source: (null)

    Thanks,

    #296826

    Re: Creating Global Groups from a text file

    I spent 4 hours on :google:

    Avatar
    bio
    Member
    #360537

    Re: Creating Global Groups from a text file

    This will get you on track.. I mostly use excel to import things…
    In this script you only need to change ditrubtion groups to global groups property

    hxxp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/1f9320e0-afaf-4387-8de5-97e4e80d5f9d

    bio…

    Avatar
    Ossian
    Moderator
    #179951

    Re: Creating Global Groups from a text file

    I don’t see you appending the full path to cn=groupname — it should (IIRC) go through OU and DC as well:
    cn=groupname,ou=targetou,dc=company,dc=corp

    (obviously put your own info in)

    Rems
    Rems
    Moderator
    #227569

    Re: Creating Global Groups from a text file

    Here,

    Code:
    Set objNewGroup = objOU.Create(“Group”, “cn=”& GroupName)[/CODE]
    where [COLOR=”Orange”]”cn=”& GroupName[/COLOR] should be [COLOR=”orange”]”cn=”& strGroup[/COLOR] because “GroupName” is an undefined variable.

    Furhermore, to prevent possible other issues you can consider some the sample code in the script below.
    [code]
    Const ForReading = 1
    Dim objTextFile, strGroup, intSize

    With CreateObject(“Scripting.FileSystemObject”)
    Set objTextFile = .OpenTextFile _
    (“[COLOR=”Blue”]c:groupnames.txt[/COLOR]”, ForReading)
    intSize = 0
    Do Until objTextFile.AtEndOfStream
    strGroup = trim(objTextFile.ReadLine)
    If strGroup Empty then
    ReDim Preserve arrGroups(intSize)
    arrGroups(intSize) = strGroup
    intSize = intSize + 1
    End If
    Loop
    objTextFile.Close: Set objTextFile = Nothing
    End With
    If not IsArray(arrGroups) _
    Then wscript.echo “No Groups!”: wscript.quit(0)

    ‘## check point ##
    ‘ For Each strGroup in arrGroups
    ‘ wsh.echo “[“& strGroup &”]”
    ‘ Next ‘#####

    Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
    Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
    Dim objRootDSE, strDNSDomain, adsPathOU, objOU
    Dim objNewGroup

    Set objRootDSE = GetObject(“LDAP://RootDSE”)
    strDNSDomain = objRootDSE.Get(“DefaultNamingContext”)

    adsPathOU = “LDAP://[COLOR=”Blue”]OU=LDAPApplications,OU=Groups[/COLOR],” & strDNSDomain

    On Error Resume Next
    Set objOU = GetObject(adsPathOU)
    If err.Number 0 Then wscript.echo _
    “specified OU does not exist!”: wscript.quit(0)

    For Each strGroup in arrGroups
    Set objNewGroup = objOU.Create(“Group”, “cn=” & strGroup)
    objNewGroup.Put “sAMAccountName”, strGroup
    objNewGroup.Put “groupType”, ADS_GROUP_TYPE_GLOBAL_GROUP Or _
    ADS_GROUP_TYPE_SECURITY_ENABLED

    objNewGroup.SetInfo
    Next

    wscript.echo “done”

    Rems

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.