Below the VBscript code which is used to create Bulk groups in AD
'-----------------------------------------------------------------------
' This script is intended to meet the creation of bulk user groups in AD
' you need to run this script on server where you have excel application installed
' and access to AD. Create a excel file with Five columns A1=Group name, B1=Group type
' C1=Description, D1=MemberOf and E1=Result
' Note: You need to mention Group name and Group type as (local or global) and description (optional) ' and memberOf (optional) as input to execute the script. Name the Excel file as Groups.xls place it on ' C: drive.
On Error Resume Next
Const ADS_GROUP_LOCAL = &h4
Const ADS_GROUP_SECURITY = &h80000000
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objError = CreateObject("Scripting.Dictionary")
Set objRootDSE = GetObject("
LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.open("C:\Groups.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
objExcel.DisplayAlerts = False
objError.CompareMode = 1
i=2
' Edit OU details here as in which OU groups to be created
Set objOU = GetObject("
LDAP://OU=Groups,OU=TestOU,"& StrDNSDomain)
Do Until objExcel.Cells(i, 1).Value = ""
strGroup = objExcel.Cells(i, 1).Value
Set objGroup = objOU.Create("Group", "cn="& StrGroup)
objGroup.Put "sAMAccountName", StrGroup
If LCase(objExcel.Cells(i, 2).Value) = "local" Then
objGroup.Put "groupType", ADS_GROUP_LOCAL Or ADS_GROUP_SECURITY
End If
objGroup.Put "description", objExcel.Cells(i, 3).Value
objGroup.SetInfo
If Err.Number <> 0 Then
objError.Add strGroup, "Failed - " & Err.Description
Err.Clear
Else
objError.Add strGroup, "Successfully Created"
End If
Set ObjGroup = nothing
objExcel.Cells(i,5).value = objError.Item(StrGroup)
i = i + 1
Loop
' Output will be edited on the same excel sheet on column E
objWorkbook.Saveas("C:\Groups.xls")
objExcel.Quit
Wscript.echo "Done"
'-------------------------------------------------------------------------------------------------
***Share your comments about this post***