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.