Use get-date inside get-aduser filter

why doesn’t this work?

get-aduser -filter {passwordlastset -lt (get-date)}

these both work:

$date = get-date
get-aduser -filter {passwordlastset -lt $date}
get-aduser -filter {passwordlastset -lt “Friday, May 20, 2022 10:23:47 AM”}

i found a technet forum that suggested some $ and quote syntax. these next ones do not throw any error, but also do not find any results:

get-aduser -server student.dom -filter {passwordlastset -lt “$(get-date)”}
get-aduser -server student.dom -filter {passwordlastset -lt “$((get-date))”}

even though “$((get-date))” returns “05/20/2022 10:34:26”, and, again, this works:

get-aduser -server student.dom -filter {passwordlastset -lt “05/20/2022 10:34:26”}

even this gross thing works:

get-date | % {get-aduser -filter {passwordlastset -lt $_}}

and of course this works very slowly: get-aduser -filter * | ? passwordlastset -lt (get-date)

Try this

$Date = Get-Date
Get-ADUser -Filter 'passwordlastset -lt $Date'
1 Like

Sometimes filtering inside brackets does not work as desired
get-aduser -filter “passwordlastset -lt ‘$(get-date)’”