Such requirements come to picture many times in different forms. Below is piece of code which can be used for such requirements. I have made it recursive to all subdirectories also.
- clear
- #--Change the name with directory you want to visit --#
- $dir_to_look="C:\Users\admin\Desktop"
- #--You may change the number of days of your choice --#
- $seven_days_backdate=$(Get-Date).AddDays(-7)
- #--Find the files which are modified or created within last 7 days --#
- Get-Childitem $dir_to_look -Recurse | `
- where-object {!($_.psiscontainer)} | `
- where { $_.LastWriteTime -gt $seven_days_backdate } | `
- foreach { Write-Host "$($_.LastWriteTime) :: $($_.Fullname) " }
Hi som, any way to export results to CSV?
ReplyDeleteTo export to csv modify the last line to the below.
ReplyDeleteforeach {Write-Output "$($_.LastWriteTime) :: $($_.Fullname) " >> C:\scripts\dir2.csv }
don't forget to change the C:\scripts\dir2.csv to the location on your machine where you would like the csv file exported.