finding out user

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Abhi
 
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
 
Hi Richard,
I tried it but it gave me the following error upon executing

Microsoft VBScript compilation error: Expected statement.
 
It looks like when I pasted the code into the post, many carriage returns
were added. Your error message will indicate the line number in the script
where the error was raised. It sounds like one of my statements that uses a
line continuation character, the "_", to continue the statement on the next
line got a carriage return inserted. The next line is a blank instead of the
rest of the line.

I would try removing any blank lines after any statements that end with "_".

Also, often word wrapping messes up lines that are pasted in a message. It's
possible that one of the lines was broken up into 2 lines. If so, you will
need to remove the extra carriage return, making the statement one line
again. In fact, that's why I use the line continuation characters, to avoid
this.

If you aren't used to this it can be tricky, but the error message should
indicate the line with the problem.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Abhi said:
Hi Richard,
I tried it but it gave me the following error upon executing

Microsoft VBScript compilation error: Expected statement.
 
Back
Top