Question : Search active directory by Date Created

I need to search an active directory for objects created recently, Is there such a way?

SBS 2003

Answer : Search active directory by Date Created

Hi,
Below script will help you...!

Modify the date:
This denotes Objects created between 01/12/2009 and 31/Dec/2009.

dtmCreationDate1 = "20091201000000.0Z"
dtmCreationDate2 = "20091231000000.0Z"

Also modify Domain
india.microsoft.com to your domain
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

dtmCreationDate1 = "20091201000000.0Z"
dtmCreationDate2 = "20091231000000.0Z"

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 'LDAP://dc=india,dc=microsoft,dc=com' WHERE objectClass='user' "  & _
        "AND whenCreated>='" & dtmCreationDate1 & "' AND whenCreated<='" & dtmCreationDate2 & "'" 
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Name").Value, objRecordSet.Fields("whenCreated").Value
    objRecordSet.MoveNext
Loop
Random Solutions  
 
programming4us programming4us