简体   繁体   中英

List of files not accessed for the last 1 year in shared folder using powershell

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM