使用 powershell 在共享文件夹中过去 1 年未访问的文件列表

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

我正在尝试获取超过一年未访问的共享文件夹中的文件列表,我给了过滤器 AddMonths(-12) 也尝试了 AddYears(-1),但不起作用,在 csv 中生成的列表包含日期为当年的文件

$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

你最好修改你的处理方式$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

使用它应该可以实现您正在寻找的东西。