Powershell tips - Filter files modified the last n days
I wanted to list files modified the last n days. Here is a filter function i wrote to help me.
1 function FilterLast([int] $nDays) 2 { 3 begin { 4 $DateToCompare = (Get-date).AddDays(-1 * $nDays) 5 } 6 7 process 8 { 9 %{ if ($_.lastwritetime –gt $DateToCompare) { $_ } } 10 } 11 }
So now i can write
ls | filterlast -nDays 4