hi all,
please i want to create a script to show me the users that only created about 10 days later specifically in 10 days not like the one below because this show me all users that created within 10 days but i want the users created exactly 10 days before only … thanks in advance …

Get-ADUser -Filter * -Properties whenCreated | Where-Object {$_.whenCreated -ge ((Get-Date).AddDays(-10)).Date}

Active Directory tracks both date and time, not just date. So instead of just getting the Date, you’re going to have to get objects that fall between midnight ten days ago and 11:59pm ten days ago.

So, your logic needs to include two comparisons.

For example:

  • First, set $start to 00:00:01 ten days ago
  • Second, set $end to 11:59:59 ten days ago
  • Compare where whenCreated -gt $start -and whenCreated -lt $end

But what you’re doing now is dragging back ALL users form the directory - that won’t work well, because in a large directory you’ll only get 1,000 or so objects anyway. You should be using the -Filter parameter of Get-ADUser to do this, not getting ALL users and then using Where-Object to filter them. If you look at the help for Get-ADUser, you’ll find that its syntax can be very similar to Where-Object.

Thanks Mr. Don Jones,

I created this three lines of code and it is working perfectly.

1- $start = ((Get-Date).AddDays(-2)) | Get-Date -Hour 00 -Minute 00 -Second 01

2- $end = ((Get-Date).AddDays(-2)) | Get-Date -Hour 23 -Minute 59 -Second 59

3- Get-ADUser -Filter * -Properties whenCreated | Where-Object {$.whenCreated -gt $start -and $.whenCreated -lt $end}

ones again thank you very much for your help … ^____^ …