CerroTorre LogoLogoEnglish translationLink zur SitemapLink zum Impressum


Link zu SelfADSI Home Link zur Linkliste Link zu FAQs
SelfADSI Home

SelfADSI - The LDAP / ADSI Scripting Tutorial
First Steps: Basic Script Examples

Vorheriges Kapitel   SelfADSI Home   Nächstes Kapitel

Imagine you are the system admin of the ADS domain 'example.com'. You want to retrieve information concerning objects in the ADS from the domain controller 'DC1' - if possible via script. And maybe you even want to alter objects and their attributes.

 

This is quite easy with the Active Directory Services Interface. Please have a look at the following script examples. If you don't know how Visual Basic scripts work, you could read the introduction for writing and running VBScripts here in the SlefADSI Tutorial first.

Example 1


First of all we want to have displayed all objects of the OU 'production':

 

Set ou = GetObject("LDAP://dc1.example.com/ou=it-admin,dc=example,dc=com")
For Each obj In ou                                            'For all objects of the OU
    WScript.Echo obj.name                                     '...show object name
Next

 

Are you confused about the function GetObject with which we have accessed the ADS directory? Then you could read more information about 'Establishing a connection to the directory' in the SelfADSI tutorial.

 

Or maybe you have got problems with the curios pathname LDAP://dc1.example.com/ou0Fabrikation,dc=example,dc=com? Then you could read the topic 'LDAP Pathnames - Distinguished Names' in the SelfADSI tutorial.

Example 2


Let's refine our example. Now we want to see all display names of user within the OU:

 

Set ou = GetObject("LDAP://dc1.example.com/ou=it-admin,dc=example,dc=com")
For Each obj In ou                                            'For all objecte of the OU...
    If (obj.Class = "user") Then                              'For user only...
        WScript.Echo obj.displayName                          '...show the displayName
        WScript.Echo obj.mail                                 '...and the mail address
    End If
Next

 

You wonder how to find out the names of attributes? Please read the detailed description of the attribute 'Class' for user objects. The description of all attributes of the object classes ADS User, ADS Contact, ADS Group, Exchange 5.5 Mailbox, Exchange 5.5 D istribution list and Exchange 5.5 Custom Recipient are available in the SelfADSI tutorial.

Example 3


Another situation: For testing purposes you want to create 500 user in the OU 'Test' fast and easily. The following script will do that for you:

 

Set ou = GetObject("LDAP://dc1.example.com/ou=Test,dc=example,dc=com")
For i = 1 To 500                                             '500x
     set user = ou.Create("user", "cn=user" & i)             ' ... create a user
    user.sAMAccountName = "user" & i                         'put log on name
    user.displayName = "user" & i                            'put displayName
    user.SetInfo                                             'write data onto the server!
Next

 

Detailed user instruction concerning creating diverse types of objects can be found in the paragraph 'Creating directory objects' here in this tutorial.


<back to top


back to SelfADSI home

Sprich Freund, und tritt ein...