Creating Multiple Objects

For experimental purposes, or to evaluate the query performance of your server configuration under stress, you may want to create a large number of directory objects of some type (usually user, computer, or group accounts). The following program will help you to perform this task. You can easily modify it to fit your domain environment as well as to meet your requirements of number and type of objects.

Listing 17.12. new 1000.bas — Creating Multiple Objects in Active Directory

start example
    Option Explicit    Sub Main ()    Dim strPath As string    Dim objAD As IADs    Dim objContainer As IADsContainer    Dim n As Integer    Dim nMax As Integer    Dim strName As String    nMax = 1000 'The number of new objects    strPath = "LDAP://OU=Staff, DC=net, DC=dom" 'any container you want    '***** For the WinNT provider:    ' strPath = "WinNT: //NET,domain"    ' The accounts will be created in the Users container.    Debug. Print "Connecting to " + strPath    Set objContainer = GetObject(strPath)    For n = 1 To nMax      strName = "user" + String(4 - Len(CStr(n)), "0") + CStr(n)     '********** For the LDAP provider **********     Set objAD = objContainer.Create ("user", CStr ("CN=" & strName) )     objAD.Put CStr ("sAMAccountName"), CStr (strName)     ' Statements for defining other properties can be placed here.     ' The following four statements are necessary in order to imediately     ' enable the new account:     '  objAD. SetInfo     '  strPath = objAD.ADsPath 'bind to the user object     '  Set objAD = GetObject (strPath)     '  objAD.AccountDisabled = False     ' Now, you can also set a password:     '  objAD.SetPassword "psw"     '********** For the WinNT provider **********     '  Set objAD = objContainer.Create ("user", strName)     ' The account will be enabled after creation, and you can     ' immediately set the password:     '  objAD.Setpassword "psw"     ' The WinNT provider only makes a very restricted set of user     ' properties available, including PasswordAge, PasswordExpired,     ' UserFlags, and a few others.     objAD.SetInfo     Debug.Print "User " + strName    Next    Debug.Print CStr(nMax) + " objects have been created."    Set objAD = Nothing    Set objcontainer = Nothing    End Sub 
end example

Windows  .NET Domains & Active Directory
Windows .NET Server 2003 Domains & Active Directory
ISBN: 1931769001
EAN: 2147483647
Year: 2002
Pages: 154 © 2008-2017.
If you may any questions please contact us: