Here is a quick Vbscript that can be used to create roles in ADAM. I suppose you can also use Ldifde but, I get lazy formatting the .LDF file, etc. So here is what this script does:
- It calls the input file specified when executing the script. (e.g. cscript CreateADAMRoles.vbs )
- It reads the input file, and begins the loop line by line until the end of the file. During each loop, it performs the following ADSI routines.
- Connects to LDAP defined within the Global Settings. (e.g. LDAP://localhost:389/cn=roles,dc=contoso,dc=com)
- Create a group object, naming it the value defined within the line read. (e.g. cn=Role1). It also sets the groupType value which is a required attribute to be successful.
- Upon completion, loop again.
A downloadable version can be obtained here.
Option Explicit
Dim objFSO,objFile, objOU, objGroup, objArgs
Dim strLine, sDomainDN, sInputFile
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
'GLOBAL SETTINGS - Please set these values as per your environment
sDomainDN = "localhost:389/cn=roles,dc=contoso,dc=com"
Set objArgs = WScript.Arguments
If Wscript.Arguments.Count = 0 Then
WScript.Echo ("No input file given on command line." & VbCrLf &_
" Usage: [cscript|wscript] " & WScript.ScriptName & " ")
Wscript.Quit
End If
sInputFile = objArgs(0)
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile (sInputFile, 1)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
Set objOU = GetObject("LDAP://" & sDomainDN)
Set objGroup = objOU.Create("Group", "CN=" & strLine)
WScript.Echo "Creating Group: " & strLine
objGroup.Put "groupType", "-2147483646"
objGroup.SetInfo
Loop
objFile.Close