SungHoon_Kim

Scripts to create users for AD LDS

Blog Post created by SungHoon_Kim Employee on Mar 23, 2016

While trying to reproduce customer's issues, at times we need to create a userstore and populate lots of users, groups, OUs and etc.

In order to make things easier, I did have to write a script to perform this and also remove them when needed.

 

In the following sample, this script will create users under "OU=People,DC=SSO,DC=LAB".

You need to ensure this OU exist before running the script.

 

CreateUsers_adlds.vbs

Const SERVER = "localhost:389"

Const ROOT = "OU=People,dc=SSO,dc=LAB"

LDAPPATH = "LDAP://" & SERVER

WScript.Echo "Connecting to ADAM instance..."

set oTopContainer = GetObject(LDAPPATH & "/" & ROOT)

WScript.Echo "LDAP Server: " &LDAPPATH & newLine

 

 

 

 

Const ADS_PROPERTY_APPEND = 3

Dim objRoot, objDomain, objOU, objOUsub, objGroup, objUser

Dim ouNo, groupNo, userNo, ouSubNo

Dim defaultPassword

defaultPassword = "defaultP@ssw0rd"

Dim ouCounter

ouCounter = 0

Dim ouSubCounter

ouSubCounter = 0

Dim groupCounter

groupCounter = 0

Dim userCounter

userCounter = 0

 

 

 

 

set objDomain = oTopContainer

WScript.Echo "Click to start creating Users"

 

 

For ouNo = 1 To 100

On Error Resume Next

Set objOU=objDomain.Create("organizationalUnit", "OU=OU" & ouNo)

objOU.Put "Description", "Sample Users for OU" & ouNo

objOU.SetInfo

ouCounter = ouCounter +1

 

 

    For groupNo = 1 To 100

    On Error Resume Next

    Set objGroup = objOU.Create("Group", "cn=OU" & ouNo & "Group" & groupNo)

    objGroup.Put "CN", "OU" & ouNo & "Group" & groupNo

    objGroup.SetInfo

    groupCounter = groupCounter +1

        For userNo = 1 To 100

        On Error Resume Next

        Set objUser = objOU.Create("User", "cn=" & "OU" & ouNo & "Group" & groupNo & "User" & userNo)

        objUser.Put "CN", "OU" & ouNo & "Group" & groupNo & "User" & userNo

        objUser.Put "sn", "OU" & ouNo & "Group" & groupNo

        objUser.Put "givenName", "User" & userNo

        objUser.Put "name", "OU" & ouNo & "Group" & groupNo & "User" & userNo

        objUser.Put "msDS-UserAccountDisabled", "FALSE"

        objUser.SetInfo

        userCounter = userCounter +1

 

 

        objUser.SetPassword defaultPassword

        objUser.AccountDisabled = False

        objUser.SetInfo

 

 

        objGroup.PutEx ADS_PROPERTY_APPEND, "member", _   

        Array("cn=" & "OU" & ouNo & "Group" & groupNo & "User" & userNo & ",OU=OU" & ouNo & "," & objRoot.Get("defaultNamingContext"))

        objGroup.SetInfo

        Next

    Next

Next

WScript.Echo ouCounter & " OUs Created. " & groupCounter & " groups created with total of " & userCounter & " users."

 

DeleteUsers_adlds.vbs

Const SERVER = "localhost:389"

Const ROOT = "OU=People,DC=SSO,DC=LAB"

LDAPPATH = "LDAP://" & SERVER

WScript.Echo "Connecting to ADAM instance..."

set oTopContainer = GetObject(LDAPPATH & "/" & ROOT)

WScript.Echo "LDAP Server: " &LDAPPATH & newLine

 

 

 

 

 

 

'Option Explicit

Const ADS_PROPERTY_APPEND = 3

Dim objRoot, objDomain, objOU, objOUsub, objGroup, objUser

Dim ouNo, groupNo, userNo, ouSubNo

 

Dim ouCounter

ouCounter = 0

Dim groupCounter

groupCounter = 0

Dim userCounter

userCounter = 0

Dim ouBaseName

ouBaseName = "OU"

 

 

 

 

set objDomain = oTopContainer

WScript.Echo "Click to start deleting Users"

 

 

For ouNo = 1 To 100

On Error Resume Next

Set objOU=GetObject(LDAPPATH & "/" & "OU=" & ouBaseName & ouNo & "," & ROOT)

 

 

    For groupNo = 1 To 100

    On Error Resume Next

        For userNo = 1 To 100

        On Error Resume Next

        objOU.Delete "User", "cn=" & ouBaseName & ouNo & "Group" & groupNo & "User" & userNo

        userCounter = userCounter +1

        Next

    objOU.Delete "Group", "cn=" & ouBaseName & ouNo & "Group" & groupNo

    groupCounter = groupCounter +1

    Next

 

 

objDomain.Delete "OrganizationalUnit", "OU=" & ouBaseName & ouNo

ouCounter = ouCounter +1

Next

 

 

WScript.Echo ouCounter & " OUs, " & groupCounter & " groups and " & userCounter & " users removed."

 

Hope it helps.

Outcomes