Al,

Here's an example of what I think you're looking for.  I did something
similar for someone else on this list awhile back for the 'whenChanged'
attribute.

Hope this helps,
Richard



option explicit

dim DNPath, ChangeVal, Com, con, rs 

Public Const ADS_SCOPE_BASE = 0
Public Const ADS_SCOPE_ONELEVEL = 1
Public Const ADS_SCOPE_SUBTREE = 2
  
Set con = CreateObject("ADODB.Connection")
Set com =   CreateObject("ADODB.Command")

con.Provider = "ADsDSOObject"
con.Properties("User ID") = "DOMAIN\userid"
con.Properties("Password") = "password"

con.Open "Active Directory Provider"

Set Com.ActiveConnection = con

DNPath = "LDAP://SERVERNAME/CN=Users,DC=mycompany,DC=com";

' alternative queries
'DNPath = "LDAP://SERVERNAME/CN=users,...,DC=com";
'DNPath =
"LDAP://SERVERNAME/OU=employees,...,DC=childdomain,DC=mycompany,DC=com";

' bastardized DMTF time for 10/28/2002
ChangeVal = 20021028000000 

' use for all users created *on or after* the specified date
Com.CommandText = "SELECT name, whenCreated FROM '" & DNPath & _
                              "' WHERE objectClass = 'user' AND
objectCategory='person' AND whenCreated>='" & ChangeVal & ".0Z'" 

' use for all users created *on* the specified date
'Com.CommandText = "SELECT name, whenCreated FROM '" & DNPath & _
'                                 "' WHERE objectClass = 'user' AND
objectCategory='person' AND whenCreated='" & ChangeVal & ".0Z'" 

Com.Properties("Page Size") = 1000
'Com.Properties("Timeout") = 30
Com.Properties("searchscope") = ADS_SCOPE_SUBTREE
Com.Properties("Cache Results") = False 
Com.Properties("Sort On") = "whenCreated"

Set rs = Com.Execute

rs.MoveFirst

While Not rs.EOF
        wscript.echo "userid: " & rs.Fields("Name").Value
        wscript.echo vbTab & "(created " & rs.Fields("whenCreated").Value &
")"     
        'wscript.echo rs.Fields("Name").Name, ": ", rs.Fields("Name").Value
        'wscript.echo rs.Fields("whenCreated").Name, ": ",
rs.Fields("whenCreated").Value
        rs.MoveNext
        'wscript.echo rs.EOF
Wend



> -----Original Message-----
> From: Al Lilianstrom [mailto:al.lilianstrom@;fnal.gov] 
> Sent: Friday, November 01, 2002 4:28 PM
> To: [EMAIL PROTECTED]
> Subject: [ActiveDir] Searching on the whenCreated attrbute
> 
> 
> Does anyone know if it's possible to do wildcard searches 
> using whenCreated as part of the filter?
> 
> Say I wanted to know what user accounts were created on 
> October 29, 2002. It makes sense to me that I should be able 
> to have a filter like
> 
> (&(objectcategory=user)(whencreated=20021029*))
> 
> to find any users created that day but that fails with an 
> invalid syntax error.
> 
> Any ideas?
> 
>       al
> -- 
> 
> Al Lilianstrom
> CD/OSS/CSI
> [EMAIL PROTECTED]
> List info   : http://www.activedir.org/mail_list.htm
> List FAQ    : http://www.activedir.org/list_faq.htm
> List archive: 
> http://www.mail-archive.com/activedir%> 40mail.activedir.org/
> 
List info   : http://www.activedir.org/mail_list.htm
List FAQ    : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/

Reply via email to