[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 875
  • Last Modified:

Report of Users accounts in Domain Controller created in Last 5 days.

Hi All,

As per requirement i have to pull a report of users accounts who has been created in last 5 days. All Domain controller are running in 2008 server.

Please share me powershell command to meet my requirement.
4 Solutions
Mike KlineCommented:
I'd have test with powershell, you can use adfind too


adfind -default -f "&(objectcategory=person)(objectclass=user)(whencreated>=20120818000000.0Z)" samaccountname whencreated -tdca

More on the format of whencreated in that query here   http://blog.joeware.net/2011/04/26/2242/

whencreated is a replicated attribute.


AhmedAliShaikAuthor Commented:
I have tried the below command

Get-ADUser -Filter {whencreated -gt $date} -properties * | ft name,whencreated

I am getting the output in the below format:
name whencreated
a        date time

Can i get the output in the below format:

Name whencreated  noofdays
A       date time         2

In the no. of days i want the substraction & know how many days back the account is created . In the output it shouls be (1 to 5)
AhmedAliShaikAuthor Commented:
Mike thanks for your response.

We are not allowed to run any tool except Microsoft in our production.

Please suggest me with the powershell or any microsoft cmdlet.

Thanks .
 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Sarang TinguriaSr EngineerCommented:
Use this PS Script

Get-QADUser -CreatedAfter (Get-Date).AddDays(-5)

Open in new window

Will SzymkowskiSenior Solution ArchitectCommented:
Get-ADUser -Filter 'objectclass -eq "User"' -Properties * | Where-Object {$_.whenCreated -gt $date} | FT name,whenCreated
You can also use Active Directory to do what you're looking for.

The SIMPLEST method:

Open Active Directory
Right click "Saved Queries"
Create new Query, enter a name "ALL USERS".
Click Define Query
Select the "User" tab and for "Name" select "has a value".
Click OK.

You've generated a query for "All Users".
Now select the new query you just created.
On the menu bar, select "View", "Add/Remove Columns"
Add "Created" to the list and click ok.

Then refresh your new query. It should show ALL users along with the date their account was created. You can easily export this to Excel and trim/format as needed.
AhmedAliShaikAuthor Commented:
Hi Thinkpad,

Good to know the easy step too. As per our requirement if we have a script we can automate and run a batch file, trigger an email to customer.

I have used the Quest command given by Sarang & powershell given by others aswell which are working fine.

I completely agree with your method wen we need few thinks instantly & when we are not sure about the code.

Thanks a lot.
AhmedAliShaikAuthor Commented:
Thanks All.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now