使用PowerShell查找共享所有顶级目录中所有文件/子文件夹的最新修改date

在Windows 2003文件服务器上有一个共享的目录树,其中有大约100GB的数据。 我需要find这个共享中的所有顶级目录,每个子文件夹中的每个文件的最后修改时间没有被修改sine 1/1/11。 本质上,我正在寻找被放弃的股票。

目录结构如下所示:

-a --a1 --a2 --a3 ----a3_1 -b --b1 --b2 -c --c1 ----c1_1 etc 

我想要做的是找出是不是a或b或c下的隐藏文件的所有东西都在1/1/11之前或之后。

到目前为止,我可以find每个文件一年后的MOD时间:

 get-childitem "\\server\h$\shared" -recurse | where-object {$_.mode -notmatch "d"} | where-object {$_.lastwritetime -lt [datetime]::parse("01/01/2011")} 

我不知道该怎么做,就是单独检查每个顶层目录,看看其中包含的所有文件是否大于一年。 有任何想法吗?

我想你只是想看看文件修改时间。 不知道你想要做什么关于文件夹,其中只包含一年未修改的子文件夹。 我也不知道是否通过“每个顶级目录” ,你的意思是abcaa1a2

以下内容查看所有目录,只列出它们不包含过去一年内写入的文件。 让我知道如果这产生你正在寻找的输出:

 $shareName = "\\server\share" $directories = Get-ChildItem -Recurse -Path $path | Where-Object { $_.psIsContainer -eq $true } ForEach ( $d in $directories ) { # Any children written in the past year? $recentWrites = Get-ChildItem $d.FullName | Where-Object { $_.LastWriteTime -gt $(Get-Date).AddYears(-1) } If ( -not $recentWrites ) { $d.FullName } } 

编辑,根据您的评论。 如果只想获取不包含过去一年中修改的文件的顶级目录,请尝试以下操作。 请注意,在非常深的/大的股票,这可能需要一段时间才能运行。

 $shareName = "\\server\share" # Don't -recurse, just grab top-level directories $directories = Get-ChildItem -Path $shareName | Where-Object { $_.psIsContainer -eq $true } ForEach ( $d in $directories ) { # Get any non-container children written in the past year $recentWrites = Get-ChildItem $d.FullName -recurse | Where-Object { $_.psIsContainer -eq $false -and $_.LastWriteTime -gt $(Get-Date).AddYears(-1) } If ( -not $recentWrites ) { $d.FullName } }