我运行了单独的Powershell命令,一个命令为我提供了特定级别所有文件夹的列表,另一个列出了所有文件夹和关联的ACL。 我想合并然后仅列出"3 级"文件夹及其关联的 ACL。 级别 3 文件夹的命令为:
Get-ChildItem "I:" -Recurse -Directory | Where-Object {$_.FullName.split("").count -le 4} | ForEach-Object FullName
文件夹 ACL 的命令为:
Get-ChildItem j: -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List
我试过了:
Get-ChildItem I: -Recurse | where-object {($_.PsIsContainer)} | Where-Object {$_.FullName.split("").count -le 4} Get-ACL | Format-List
但是得到错误 Where-Object :找不到接受参数"Get-ACL"的位置参数。
提前感谢任何帮助! 使用 PS 5.1,顺便说一句。
可以使用管道完成此操作。 只需将第一组命令的输出直接传送到 Get-ACL
cmdlet 中,如下所示。
$path = "I:"
Get-ChildItem -Path $path -Recurse -Directory | `
Where-Object {$_.FullName.split('').count -le 4} | `
Select-Object -ExpandProperty FullName | `
Get-ACL | `
Format-List
我认为您在Where-Object
之后缺少一个管道字符(|
(。
这奏效了:
dir "I:" -Recurse -ea silentlycontinue | where { $_.PsIsContainer -and $_.FullName.split("").count -le 5} | % { $path1 = $_.fullname; Get-Acl $_.Fullname | % { $_.access | where { !$_.IsInherited } | Add-Member -MemberType NoteProperty -name "Path" -Value $path1 -passthru }}
感谢您的回复!