停止文件夹递归时

Stop folder recurse when

我正在尝试执行以下操作 -

$OutFile = "C:\temp\Audit_Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile 

$RootPath = "\netapp\DATA"

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}

foreach ($Folder in $Folders){
    $ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access  }
    Foreach ($ACL in $ACLs){
    $OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference  + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
    Add-Content -Value $OutInfo -Path $OutFile
    }}

问题是我不再需要递归深入到文件夹结构的大约 3 或 4 层。我想忽略 yyyy\mm\dd 格式的数千个文件夹的可能性。 yyyy 是第一个文件夹。

所以我想对这样的事情进行审计 -

\netapp\data\folder1
\netapp\data\folder2
\netapp\data\folder2\folderA
\netapp\data\folder3
\netapp\data\folder3\folderA
\netapp\data\folder3\folderA\testfolder

但是一旦它碰到任何树中的以下部分,我希望它停止向下移动 -

\netapp\data\folder3\folderA\testfolder\yyyy

这是一种省略带有 yyyy 的文件夹名称的方法。 如果你想更精确,你可以调整RegEx部分。

$Folders = dir $RootPath -recurse | where {($_.psiscontainer -eq $true) -AND ($_.FullName -notmatch '\\d{4}($|\)'}