Search code examples
powershellpowershell-2.0

Using Get-childitem to get a list of files modified in the last 3 days


Code as it is at the moment

get-childitem c:\pstbak\*.* -include *.pst | Where-Object { $_.LastWriteTime -lt (get-date).AddDays(-3)} |

Essentially what I am trying to do is get a list of all PST files in the folder above based on them being newer than 3 days old. I'd then like to count the results. The above code doesn't error but brings back zero results (there are definitely PST files in the folder that are newer than three days. Anyone have any idea?


Solution

  • Try this:

    (Get-ChildItem -Path c:\pstbak\*.* -Filter *.pst | ? {
      $_.LastWriteTime -gt (Get-Date).AddDays(-3) 
    }).Count