You are looking for files that are written at exact time ( hours mins, secs, year, month and 2 days before). Unless the files were written to the second, two (or one) days ago, you will not find them. In other words, you were comparing full DateTime
objects and not just a date and hence there is very less chance that they were exactly equal, which seemed to suggest that -eq
doesn't work, but other comparisons do.
You probably wanted to just compare the dates, without the times:
$yesterday = (get-date).AddDays(-1).Date
gci c:\users | ?{ $_.LastWriteTime.Date -eq $yesterday}
( also moved the get-date outside, as you probably don't want to do it again and again.)