Close Menu
    Facebook X (Twitter) Instagram
    Saturday, October 11
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»SCCM 2007»VBScript to create AD security groups

    VBScript to create AD security groups

    Eswar KonetiBy Eswar KonetiMarch 29, 12:52 pm2 Mins Read SCCM 2007 1,130 Views
    Share
    Facebook Twitter LinkedIn Reddit

     

    If you are working with System Center Configuration Manager (SCCM 2007),you know what the post means here. Have been getting lot of requests per day/week to create AD security groups for new applications to deploy applications .

    Here is the VB Script that fullfil your requirememnt but test it in the lab before taking into production.

    Create a Excel file with piping all AD security group names .Change the Excel file,OU name etc from the script.

    Replace the Quotes(single and Double) as they are fancy from the post when you copy the code to vbs file.

     

    ON ERROR RESUME NEXT
    Dim strExcelPath, objExcel, objSheet, strPrevious,introw
    Dim strName, strParentDN, objParent, objGroup
    Dim strGroupType, strSecurity, lngType
    Const ADS_GROUP_TYPE_GLOBAL_GROUP = &H02
    Const ADS_GROUP_TYPE_LOCAL_GROUP = &H04
    Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &H08
    Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000

    ' Specify spreadsheet file.
    strExcelPath = "c:\scripts\Groups.xls"

    ' Open the spreadsheet.
    Set objExcel = CreateObject("Excel.Application")
    objExcel.WorkBooks.Open strExcelPath
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

    ' Skip the first row. Iterate through the remaining rows of the spreadsheet,
    ' until the first blank entry in the first column.
    intRow = 2
    ' Keep track of previous OU/Container.
    ' We only need to bind if the OU/Container is different.
    strPrevious = ""
    Do While objSheet.Cells(intRow, 1).Value <> ""
    ' Retrieve values from spreadsheet.
    strName = objSheet.Cells(intRow, 2).Value
    strGroupType = objSheet.Cells(intRow, 3).Value
    strSecurity = objSheet.Cells(intRow, 4).Value
    Select Case LCase(strGroupType)
    Case "global"
    lngType = ADS_GROUP_TYPE_GLOBAL_GROUP
    Case "local"
    lngType = ADS_GROUP_TYPE_LOCAL_GROUP
    Case "universal"
    lngType = ADS_GROUP_TYPE_UNIVERSAL_GROUP
    End Select
    If (LCase(strSecurity) = "security") Then
    lngType = lngType Or ADS_GROUP_TYPE_SECURITY_ENABLED
    End If
    If (strParentDN <> strPrevious) Then
    ' Bind to a different parent OU/Container.
    Set objParent = GetObject("LDAP://ou=managed,dc=eskonr,dc=com")
    End If
    ' Create the group.
    Set objGroup = objParent.Create("group", "cn=" & strName)
    ' Assign NetBIOS name of group.
    objGroup.Put "sAMAccountName", strName
    ' Assign the group type.
    objGroup.Put "groupType", lngType
    ' Save changes.
    objGroup.SetInfo
    strPrevious = strParentDN
    intRow = intRow + 1
    Loop

    ' Close workbook and quit Excel.
    objExcel.ActiveWorkbook.Close
    objExcel.Application.Quit
    msgbox("Done")

    Note: Please check if you have proper rights to create AD sec groups on the right OU from Script.

    Create AD security groups using Script SCCM to create AD sec groups script Security groups AD VB Script VBscript to create AD sec groups
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    Monitoring Endpoint Security Applications with SCCM ConfigMgr SQL

    October 11, 8:48 pm

    Application Deployment with Hybrid Joined Requirement Rules in Intune

    October 06, 8:59 pm

    Troubleshooting Windows KMS Activation Issues with SCCM scripts feature

    September 09, 11:07 pm

    Leave a ReplyCancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Sign Up

    Get email notifications for new posts.

    Author

    I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

    Support

    Awards

    Archives

    © Copyright 2009-2025 Eswar Koneti, All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.