Skip navigation

Q. How can I create a list that includes all user profiles in a particular container and the date and time they were created?

A. I've created the following script, listusers.vbs, which passes the name of a Lightweight Directory Access Protocol (LDAP) container, then uses this name to generate a list all user profiles in the container and their creation date (GMT). You can download the script at Code. Save the script as listusers.vbs. Remember to modify it to include information specific to your installation.

' John Savill 19 August 2004
Option Explicit

Dim strLdapPath, objConnection, objChild, dtmCreate

' Check that all required arguments have been passed.
If Wscript.Arguments.Count  required. For example:" & vbCrLf _
    & "cscript listusers.vbs ou=testing,dc=demo,dc=test"
End If

strLdapPath = Wscript.Arguments(0)

Set objConnection = GetObject("LDAP://" & strLdapPath)
objConnection.Filter = Array("user")

For Each objChild In objConnection
    objChild.GetInfoEx Array("createTimeStamp"), 0
    dtmCreate = objChild.Get("createTimeStamp")

    WScript.Echo objChild.Name & vbTab & dtmCreate


Wscript.Echo "Operation Completed"

I place the cscript command at the beginning of the call to the listusers.vbs file. Specifying cscript forces the script to run in the CScript (i.e., command window) environment. If you don't specify cscript, each user in the list will be displayed in a dialog box. In the sample code here, the passed LDAP container is an organizational unit (OU) called testing (ou=testing) in the demo.local domain (dc=demo,dc=local).

To run the script, at a command prompt enter

cscript listusers.vbs ou=testing,dc=demo,dc=local

You'll see output on screen that's similar to this:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

CN=Barry Allen 6/2/2004 10:59:32 PM
CN=Bruce Wayne 6/11/2004 6:30:40 PM
CN=Clark Kent 6/2/2004 10:55:14 PM
CN=DeleteMe 8/19/2004 4:02:04 PM
Operation Completed
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.