PS 获取没有文件的文件夹的脚本

PS script to get the folder with no files

我正在尝试创建一个 PS 脚本,它将遍历目录中的文件夹和子文件夹,然后获取没有文件或超过 90 天的文件的文件夹名称。下面是文件夹结构。输出应为 VendorA 或 VendorB 或 VendorC。我尝试使用 gci 但没有得到所需的输出。

FTP
    VendorA
        folderA
            folder D
        folderB
            Folder E
            Folder F
            Folder G
        folderC
    VendorB
        folderA
            folder D
        folderB
            Folder E
            Folder F
            Folder G
        folderC
    VendorC
        folderA
            folder D
        folderB
            Folder E
            Folder F
            Folder G
        folderC

这是我尝试过的代码,它确实得到了输出,但是我需要它的 csv 表格格式 - 名称、创建时间

    $gci = gci -Path F:\ftp\NEWFTP -Directory

foreach ($g in $gci)
{
   $child =  Get-ChildItem -Path $g.FullName -Recurse -File
       if ($child -eq $null)
       {
         $g.Name, ($g.CreationTime).ToShortDateString() | Out-File C:\Users\test\Documents\folders.txt -Append
       }
}

要return文件夹x的空子文件夹您需要:

gci -Path x -Recurse -Directory|%{ if( $null -eq (gci $_.fullname) )  {$_.fullname}} 

你的要求我不是很清楚。

  • 将 90 天解释为 MinAge:
  • 如果反之则将 -gt 更改为 -le

## Q:\Test18\SO_51443077.ps1

Push-Location 'F:\Ftp\NewFTP'

$Vendors= Get-ChildItem * -Directory
$MinAge = (Get-Date).AddDays(-90)

ForEach($Vendor in $Vendors){
   If ((!(Get-ChildItem -Path $Vendor.FullName -File -Recurse).Count) -Or
       (!(Get-ChildItem -Path $Vendor.FullName -File -Recurse |
            Where LastWriteTime -gt $MinAge).Count)) {
      "Folder {0} has no file(s) / (newer than {1}" -f $Vendor,$MinAge
   }
}
Pop.Location

我去年测试文件夹的示例输出

Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05
Folder Q:\Test17 has no file(s) / (newer than 2018-04-21 16:26:05