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 ..
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.
– 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.