Forum Search:
Forum.Brain-Cluster.com: Brain Cluster Technical Forum
Ultimate forum for Technical Discussions

Home » Microsoft » Windows Server » Active Directory » Finding users created within the last week
Finding users created within the last week [message #161565] Thu, 01 October 2009 07:27 Go to next message
Scary Fruit  is currently offline Scary Fruit  United Kingdom
Messages: 7
Registered: October 2009
Junior Member
Hi all,

Could someone tell me how I can find all users created within the last week?
I'm running Windows 2003 R2 SP2.

Thanks,

Curtis.

--
Please reply to newsgroup only.
Re: Finding users created within the last week [message #161586 is a reply to message #161565] Thu, 01 October 2009 18:48 Go to previous messageGo to next message
rlmueller-nospam  is currently offline rlmueller-nospam  United States
Messages: 292
Registered: July 2009
Senior Member
"Scary Fruit" <x@x.com> wrote in message
news:O8vT%23rpQKHA.1268@TK2MSFTNGP04.phx.gbl...
> Hi all,
>
> Could someone tell me how I can find all users created within the last
> week? I'm running Windows 2003 R2 SP2.
>
> Thanks,
>
> Curtis.
>
> --
> Please reply to newsgroup only.

You can use ADO in a VBScript program to do this. See this link for tips:

http://www.rlmueller.net/ADOSearchTips.htm

From the link above, and using the same syntax, the filter for all user
objects created since September 24, 2009, would be:

strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(whenCreated>=20090924000000.0Z))"

A VBScript program that calculates the date one week in the past, uses ADO
to query AD for users created since then, and retrieves the values of the
sAMAccountName and distinguishedName attributes would be (not tested):
================
Option Explicit

Dim objRootDSE, strDNSDomain, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim dtmStart, strStart
Dim strDN strNTName

' Determine date 7 days ago.
dtmStart = DateAdd("d", -7, Now())
strStart = CStr(Year(dtmStart)) _
& Right("0" & CStr(Month(dtmStart)), 2) _
& Right("0" & CStr(Day(dtmStart)), 2) & "000000.0Z"

' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"

Set adoRecordset = CreateObject("ADODB.Recordset")
adoRecordset.ActiveConnection = adoConnection

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on all users created in last 7 days.
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(whenCreated>=" & strStart & "))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,sAMAccountName"

' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
adoRecordset.Source = strQuery
adoRecordset.Open

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strDN = adoRecordset.Fields("distinguishedName").Value
strNTName = adoRecordset.Fields("sAMAccountName").Value
Wscript.Echo strDN & " (" & strNTName & ")"
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Re: Finding users created within the last week [message #161613 is a reply to message #161586] Fri, 02 October 2009 09:42 Go to previous messageGo to next message
rlmueller-nospam  is currently offline rlmueller-nospam  United States
Messages: 292
Registered: July 2009
Senior Member
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:uNs2RovQKHA.4428@TK2MSFTNGP02.phx.gbl...
>
> "Scary Fruit" <x@x.com> wrote in message
> news:O8vT%23rpQKHA.1268@TK2MSFTNGP04.phx.gbl...
>> Hi all,
>>
>> Could someone tell me how I can find all users created within the last
>> week? I'm running Windows 2003 R2 SP2.
>>
>> Thanks,
>>
>> Curtis.
>>
>> --
>> Please reply to newsgroup only.
>
> You can use ADO in a VBScript program to do this. See this link for tips:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> From the link above, and using the same syntax, the filter for all user
> objects created since September 24, 2009, would be:
>
> strFilter = "(&(objectCategory=person)(objectClass=user)" _
> & "(whenCreated>=20090924000000.0Z))"
>
> A VBScript program that calculates the date one week in the past, uses ADO
> to query AD for users created since then, and retrieves the values of the
> sAMAccountName and distinguishedName attributes would be (not tested):
> ================
> Option Explicit
>
> Dim objRootDSE, strDNSDomain, adoConnection
> Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
> Dim dtmStart, strStart
> Dim strDN strNTName
>
> ' Determine date 7 days ago.
> dtmStart = DateAdd("d", -7, Now())
> strStart = CStr(Year(dtmStart)) _
> & Right("0" & CStr(Month(dtmStart)), 2) _
> & Right("0" & CStr(Day(dtmStart)), 2) & "000000.0Z"
>
> ' Determine DNS domain name.
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
>
> ' Use ADO to search Active Directory.
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
>
> Set adoRecordset = CreateObject("ADODB.Recordset")
> adoRecordset.ActiveConnection = adoConnection
>
> ' Search entire domain.
> strBase = "<LDAP://" & strDNSDomain & ">"
>
> ' Filter on all users created in last 7 days.
> strFilter = "(&(objectCategory=person)(objectClass=user)" _
> & "(whenCreated>=" & strStart & "))"
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "distinguishedName,sAMAccountName"
>
> ' Construct the LDAP query.
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
>
> ' Run the query.
> adoRecordset.Source = strQuery
> adoRecordset.Open
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
> ' Retrieve values.
> strDN = adoRecordset.Fields("distinguishedName").Value
> strNTName = adoRecordset.Fields("sAMAccountName").Value
> Wscript.Echo strDN & " (" & strNTName & ")"
> adoRecordset.MoveNext
> Loop
>
> ' Clean up.
> adoRecordset.Close
> adoConnection.Close
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>

I should point out that you can also use the filter I suggested with Joe
Richards' adfind utility. See this link:

http://www.joeware.net/freetools/tools/adfind/index.htm

The command would be similar to (watch line wrappting, this is one line):

adfind -b "dc=MyDomain,dc=com" -f
"(&(objectCategory=person)(objectClass=user)(whenCreated >=20090924000000.0Z))"
sAMAccountName

You need to specify the date, but you might be able to devise a batch file
that constructs the date one week in the past, similar to what I did in the
VBScript program I posted earlier.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Re: Finding users created within the last week [message #162076 is a reply to message #161565] Wed, 14 October 2009 14:17 Go to previous message
SubstituteThisWithMyF  is currently offline SubstituteThisWithMyF  Netherlands
Messages: 85
Registered: October 2009
Member
adfind -default -f
"(&(objectCategory=person)(objectClass=user)(whenCreated >=20091007010101.OZ))"
sAMAccountName whenCreated

20091007010101.OZ format is YYYYMMDDHHMMSS
--

Cheers,
(HOPEFULLY THIS INFORMATION HELPS YOU!)

# Jorge de Almeida Pinto # MVP Identity & Access - Directory Services #

BLOG (WEB-BASED)--> http://blogs.dirteam.com/blogs/jorge/default.aspx
BLOG (RSS-FEEDS)--> http://blogs.dirteam.com/blogs/jorge/rss.aspx
------------------------------------------------------------ ------------------------------
* This posting is provided "AS IS" with no warranties and confers no rights!
* Always test ANY suggestion in a test environment before implementing!
------------------------------------------------------------ ------------------------------
#################################################
#################################################
------------------------------------------------------------ ------------------------------

"Scary Fruit" <x@x.com> wrote in message
news:O8vT#rpQKHA.1268@TK2MSFTNGP04.phx.gbl...
> Hi all,
>
> Could someone tell me how I can find all users created within the last
> week? I'm running Windows 2003 R2 SP2.
>
> Thanks,
>
> Curtis.
>
> --
> Please reply to newsgroup only.
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 4507 (20091014) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>

__________ Information from ESET Smart Security, version of virus signature database 4507 (20091014) __________

The message was checked by ESET Smart Security.

http://www.eset.com
Previous Topic:Format of AD Manager attribute
Next Topic:RODC DNS in DMZ
Goto Forum:
  


Current Time: Wed Jan 17 05:53:38 MST 2018

Total time taken to generate the page: 0.03092 seconds
.:: Contact :: Home ::Sitemap::.

Powered by: FUDforum 3.0.0RC2.
Copyright ©2001-2009 FUDforum Bulletin Board Software