【问题标题】:How to Combine Two Powershell Commands for Listing Folders and ACLs如何结合使用两个 Powershell 命令来列出文件夹和 ACL
【发布时间】:2018-04-16 20:43:50
【问题描述】:

我运行了单独的 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。

【问题讨论】:

    标签: powershell


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      我认为您在 Where-Object 之后缺少一个竖线字符 (|)。

      【讨论】:

        【解决方案3】:

        这行得通:

        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 }}
        

        感谢您的回复!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-01-14
          • 1970-01-01
          • 2021-12-23
          • 2014-12-26
          • 1970-01-01
          • 1970-01-01
          • 2014-09-19
          相关资源
          最近更新 更多