Results 1 to 3 of 3

Thread: DSQUERY: list users created after a specific date

  1. #1
    Join Date
    Nov 2008
    Posts
    1

    DSQUERY: list users created after a specific date

    Hi all GURUS!

    I am in urgent need of help.
    Trying to figure out HOW to do a DSQUERY and list ALL users in a OU (+sub ou's) that has a creation date after 2008-01-01.

    Anyone who can be humble enough to help me out?

  2. #2
    Join Date
    Jun 2006
    Posts
    623

    Re: DSQUERY: list users created after a specific date

    There is tool called AdFind when querying Active Directory, you can download it from the website called joeware.net, it will work properly for with the below:

    adfind -gc -b -f "&(objectclass=user)(ObjectCategory=person (whenCreated>=20080101000000.0Z)"
    sAMAccountname, createTimeStamp

  3. #3
    Join Date
    Nov 2005
    Posts
    1,187

    Re: DSQUERY: list users created after a specific date

    Check the below VBscript and see if that works for you:

    Code:
    On Error Resume Next
    
    Const ADS_SCOPE_SUBTREE = 2
    
    dtmCreationDate1 = "20110131000000.0Z"
    
    Set objShell = CreateObject("Wscript.Shell")
    
    'Verifies script was run using Cscript, and if not relauches it using Cscript
    If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
        objShell.Popup "Relaunching script with Cscript in 5 seconds...", 5, _
        "Script Host Message", 48
        objShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & _
        DQ & WScript.scriptFullName & DQ, 1, False
        WScript.Quit 0
    End If
    
    'Construct an ADsPath to the Current Domain with rootDSE
    Set objRootDSE = GetObject("LDAP://rootDSE")
    strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    
    objCommand.CommandText = _
    "SELECT Name, whenCreated FROM '" & strADsPath & "' WHERE objectClass='user' " & _
    "AND whenCreated>='" & dtmCreationDate1 & "'"
    Set objRecordSet = objCommand.Execute
    
    objRecordSet.MoveFirst
    
    Do Until objRecordSet.EOF
        WScript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
        objRecordSet.MoveNext
    Loop

Similar Threads

  1. DSQuery list user for entire forest
    By kennyja in forum Active Directory
    Replies: 3
    Last Post: 03-01-2014, 03:52 PM
  2. Replies: 2
    Last Post: 30-04-2009, 09:45 PM
  3. dsquery to list members of group
    By joey in forum Windows Server Help
    Replies: 1
    Last Post: 05-11-2008, 08:43 AM
  4. List of Last Logon Time with dsget/dsquery
    By Viensterrr in forum Active Directory
    Replies: 1
    Last Post: 17-09-2008, 05:36 PM
  5. dsquery for users last logon time???
    By Delil in forum Active Directory
    Replies: 4
    Last Post: 13-07-2005, 12:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,342,858.65138 seconds with 16 queries