使用powershell枚举当前目录的ACL



我被分配了以下任务。创建foreachloop。您可以使用以下模板:

$directory-variable-here
foreach ($item in $directory) {
Script block here
}

foreachcondition之上,将变量$directory设置为当前目录的内容。将脚本块占位符替换为枚举文件ACL的命令,使用$itemvariable代替文件名。您需要使用以下cmdlet:GetChildItem(或GetChildItem的任何别名,如lsor-dir(获取Acl

我需要一些帮助来解决这个问题。其次,什么可以用来存储当前的目录路径,我很困惑。

到目前为止,我已经尝试了以下脚本,但它只返回当前目录的内容,而不是子目录的内容。

$dirpath= $PSScriptRoot

foreach ($item in $dirpath){
$var = Get-ChildItem $item
Get-Acl $var
}

我尝试了很多,经过一些搜索,我找到了解决方案,这是脚本

$mypath= $PSScriptRoot
$var = Get-ChildItem -Recurse -Path $mypath
foreach ($item in $var){
Get-Acl $item.FullName

}

最新更新