Reputation: 77
I am trying to get a list of files in shared folder not accessed for more than one year , i gave the filter AddMonths(-12) also tried AddYears(-1) , doesnt work, list generated in csv contains file having date as current year
$time = Get-Date
$time.AddMonths(-12)
get-childitem "\\Ajay-1\" -Recurse -File -ErrorAction SilentlyContinue| Where-
Object {$_.LastAccessTime -lt $time} | select fullname,lastaccesstime |
export-csv "D:\Time\Last.csv" -notypeinfo
Upvotes: 0
Views: 1494
Reputation: 1450
You'd have better luck modifying how you're handling $time
$time = (Get-Date).AddDays(-365)
$path = "C:\"
Get-ChildItem -Path $path -Recurse -Force | Where-Object {$_.LastAccessTime -lt $time} | select fullname,lastaccesstime |export-csv "D:\Time\Last.csv" -notypeinfo
Using this should achieve what you're looking for.
Upvotes: 1