$date = [datetime](\"05/19/2014\")
gci -Recurse | Select-Object FullName,LastWriteTime | Where-Object { $_.LastWriteTime.ToShortDateString() -ge $date.ToShortDateString(
The issue may be in how you are doing your comparison. The DateTime.ToShortDateString method uses whatever the short date pattern for the current culture your process is using. Unfortunately, I can't think of an example that would make a date in 2009 appear to be greater than a date in 2014 in string form. Try just comparing the date-time object directly. You could just compare dates by using the Date
property as such:
$date = [datetime]("05/19/2014")
gci -Recurse | Select-Object FullName,LastWriteTime | Where-Object { $_.LastWriteTime.Date -ge $date } | Format-Table -AutoSize
Note that I did not need to use the Date
property on your $date
variable, as when instantiating a DateTime
object with only date information, the time is set to 12:00 AM. The Date
property will provide a value with the date of the original DateTime
object but with the time set to 12:00 AM.
The -AutoSize
parameter I added to Format-Table
will take care of your second question, as it will automatically resize columns to a sane width.