Abhi said:
How can I find out users based on the user account creation date? I have
tried a sample script which is givne in Technet, but it is failing.Any
pointers are highly appreciated
You can use ADO in a VBScript program to retrieve attributes of objects that
meet conditions. In this case, the whenCreated attribute can be used to
filter user objects. See this link for information on using ADO:
http://www.rlmueller.net/ADOSearchTips.htm
The whenCreated attribute is generalized time in the form yyyymmddhhnnss.0Z
(where nn is minutes). For example, to retrieve the NT names (pre-Windows
2000 logon name) and Distinguished Names of all users created during the day
June 20, 2007:
==========
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strDN
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on user objects created after midnight 6/20/2007 and
' before midnight 6/21/2007.
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(whenCreated>=20070620000000.0Z)(whenCreated<=20070621000000.0Z))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,distinguishedName"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strName = adoRecordset.Fields("sAMAccountName").Value
strDN = adoRecordset.Fields("distinguishedName").value
Wscript.Echo "NT Name: " & strName & ", DN: " & strDN
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close