0
votes

I have separate Powershell commands I run, one gets me a list of all folders at a specific level, the other list all folders and associated ACLs. I'd like to combine then to list only "level 3" folders, and their associated ACLs. Command for level 3 folders is:

    Get-ChildItem "I:" -Recurse -Directory | Where-Object {$_.FullName.split("\").count -le 4} | ForEach-Object FullName 

Command for folder ACLs is:

    Get-ChildItem j:\ -Recurse | where-object {($_.PsIsContainer)} | Get-ACL | Format-List 

I tried:

    Get-ChildItem I:\ -Recurse | where-object {($_.PsIsContainer)} | Where-Object {$_.FullName.split("\").count -le 4} Get-ACL | Format-List

But got error Where-Object : A positional parameter cannot be found that accepts argument 'Get-ACL'.

Thanks in advance for any help! Using PS 5.1, btw.

3

3 Answers

1
votes

You can accomplish this by using the pipeline. Simply pipe the output of your first set of commands directly into the Get-ACL cmdlet, like so.

$path = "I:\"
Get-ChildItem -Path $path -Recurse -Directory | `
    Where-Object {$_.FullName.split('\').count -le 4} | `
    Select-Object -ExpandProperty FullName | `
    Get-ACL | `
    Format-List
0
votes

I think you're missing a pipe character (|) after Where-Object.

0
votes

This worked:

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

Thanks for the responses!