【发布时间】:2015-03-25 02:17:29
【问题描述】:
我需要获取共享网络驱动器上所有文件夹所有者的列表。但是,我想将递归限制为只有 3 个文件夹深度(尽管我们告诉他们不要这样做,但我们的一些用户会创建几级深度的文件夹)。我找到了下面的脚本,并对其稍作修改以仅提供文件夹所有者(它最初为 ACL 返回了更多信息),但它仍然贯穿每个文件夹级别。如何修改它以仅返回 3 个文件夹级别?
$OutFile = "C:\temp\FolderOwner.csv" # indicates where to input your logfile#
$Header = "Folder Path;Owner"
Add-Content -Value $Header -Path $OutFile
$RootPath = "G:\" # which directory/folder you would like to extract the acl permissions#
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders){
$Owner = (get-acl $Folder.fullname).owner
Foreach ($ACL in $Owner){
$OutInfo = $Folder.Fullname + ";" + $owner
Add-Content -Value $OutInfo -Path $OutFile
}
}
【问题讨论】:
-
这涵盖了它:[限制递归][1] [1]:stackoverflow.com/questions/13249085/…
标签: powershell permissions acl powershell-3.0 directory