Manipulating Objects in the Active Directory

   

Manipulating Objects in the Active Directory

To create an object in the directory, you must first create an object of a specific class and then assign values to the mandatory attributes of the object before writing it to the directory. From this procedure, one can quickly conclude that the only thing differentiating one object from another within the directory is the class of the object and the attributes values assigned to each object.

Armed with this knowledge, you can easily enumerate, create, and remove objects in the directory using generic code syntax, and change the attribute assignments as appropriate for each object created.

Displaying All User Class Objects in the Active Directory Using Visual Basic

To enumerate all user objects in a particular container in the Active Directory, use a variation of the following Visual Basic code:

 Dim RootDSE As IADs Dim UserContainer As IADsContainer Dim User As IADs Dim RelativePathFromDomainToUserContainer As String RelativePathFromDomainToUserContainer = "ou=user accounts," Set RootDSE = GetObject("LDAP://RootDSE") Set UserContainer = GetObject("LDAP://" & RelativePathFromDomainToUserContainer & graphics/ccc.gif RootDSE.Get("DefaultNamingContext")) UserContainer.Filter = Array("User") For Each User In UserContainer     Debug.Print User.AdsPath Next 

Note

In the previous example you are using the IADsContainer Filter property to display objects belonging only to the User class.


Displaying All Group Class Objects in the Active Directory Using Visual Basic

By changing the IADsContainer Filter property value assignment (and potentially , the relative path to the groups you want to enumerate) you can display all groups defined in a particular container.

An example of such a procedure is shown in the following Visual Basic code segment:

 Dim RootDSE As IADs Dim GroupContainer As IADsContainer Dim Group As IADs Dim RelativePathFromDomainToGroupContainer As String RelativePathFromDomainToGroupContainer = "ou=Groups,ou=Chicago," Set RootDSE = GetObject("LDAP://RootDSE") Set GroupContainer = GetObject("LDAP://" & RelativePathFromDomainToGroupContainer & graphics/ccc.gif RootDSE.Get("defaultNamingContext")) GroupContainer.Filter = Array("Group") For Each Group In GroupContainer     Debug.Print Group.AdsPath Next 

Displaying All Computer Class Objects in the Active Directory Using Visual Basic

To display all computer accounts in a particular container, use the following Visual Basic code:

 Dim RootDSE As IADs Dim ComputerAccountContainer As IADsContainer Dim ComputerAccount As IADs Dim RelativePathFromDomainToComputerContainer As String RelativePathFromDomainToComputerContainer = "ou=Workstations,ou=Computer Accounts, graphics/ccc.gif ou=Chicago" Set RootDSE = GetObject("LDAP://RootDSE") Set ComputerAccountContainer = GetObject("LDAP://"& graphics/ccc.gif RelativePathFromDomainToComputerContainer & RootDSE.Get("defaultNamingContext")) ComputerAccountContainer.Filter = Array("Computer") For Each ComputerAccount In ComputerAccountContainer     Debug.Print ComputerAccount.AdsPath Next 

   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net