Retrieving user accounts created today, but without the time

Hello and thank you to all who take the time to look at my post and offer assistance!

Currently I am trying to make a script that returns enabled users who were created today or whenever the present day is when it is run, but without the time factored into the date. Right now if I try to run the below it doesn’t return anything. I’ve tried many of the comparison operators but it still doesn’t work.

Get-ADUser -Filter "enabled -eq 'true'" -Properties name, whencreated | 
    where {$_.whencreated -like (get-date)}

Now if I instead try to find users created in the last two days as an example I can do that, but it is always taking the time into account which is what I want to ignore. I simply want it to find users created on 12/29/21 and not worry about a timestamp at all, just find anyone created on that day at ANY time.

I’ve done a lot of googling and trial and error but am having no such luck. Hopefully my post makes sense and thank you again to any who offer help!

To get only the “Date” part from the current day you can use

(Get-Date).Date

To make the reference and the AD property comparable you have to do this for both. So it looks something like this:

Get-ADUser -Filter "Enabled -eq '$true'" -Properties WhenCreated | 
    Where-Object {(Get-Date $($_.whencreated)).Date -eq  (Get-Date).Date}

BTW: The comparison operator -like is not a good choice when it comes to date and time comparisons. Instead you should use -eq or -lt or -gt or -le or -ge.

So your query could also be written like this:

Get-ADUser -Filter "Enabled -eq '$true'" -Properties WhenCreated | 
    Where-Object {$_.whencreated -ge  (Get-Date).Date}
1 Like

Olaf, FWIW, your solution work perfectly for me.