PowerShell

时间:2016-08-03 15:46:51

标签: powershell

我对此很陌生,这让我发疯了。我正在尝试在文件服务器上获取超过15年(5475天)的文件夹创建日期列表,并将其导出到Excel。

我尝试了几种不同的方法并遇到了一个我认为正在工作的方法,但事实证明它只是将所有文件夹的日期投入到.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

1 个答案:

答案 0 :(得分:1)

试试这个

Function Get-NeglectedFiles
{
  Param(
  [string[]]$path,
  [int]$numberDays)

  $cutOffDate = (Get-Date).AddDays(-$numberDays) 
  Get-ChildItem -Recurse -Path $path -Attributes Directory | 
  Where-Object CreationTime -le $cutOffDate
}
相关问题