我对此很新,它让我发疯。我试图在我们的文件服务器上获取超过15年(5475天)的文件夹创建日期列表,并将其导出到Excel。PowerShell中的文件夹创建日期列表
我已经尝试了几种不同的方法和跨一个我以为是工作来了,但事实证明,它只是抛出所有文件夹日期为.csv文件笑我知道这个代码是可能是一个灾难,所以我正在寻找一些帮助。非常感谢:)
Function Get-NeglectedFiles {
Param([string[]]$path, [int]$numberDays)
$cutOffDate = (Get-Date).AddDays(-$numberDays)
Get-ChildItem -Recurse -Path $path
Where-Object { $_.CreationTime -le $cutOffDate -and { $_.Attributes -eq 'Directory' } }
}
Get-NeglectedFiles -path "S:\Test" -numberDays 2000 |
Select-Object FullName, CreationTime |
Export-Csv -Path C:\Scripts\Test.csv -NoTypeInformation
你缺少 “|” Get-ChildItem和Where-Object之间。你的过滤器从来没有申请,因为它没有任何工作。 'Get-ChildItem -Recurse -Path $ path | Where-Object ...' –
或者你可以简化一下命令'Get-ChildItem -Recurse -Path $ path -Attributes Directory | Where-Object CreationTime -le $ cutOffDate' – Honzajscz
哦......哈。谢谢你。我会给它一个镜头。 编辑:CreationTime一块工作完美!谢谢。但它抓取所有文件类型,而不仅仅是目录。我必须尝试清理那部分。 –