I am trying to pipe the output from a foreach loop into a format command but it does not work. The reason I think is possible is because this works.
$op = foreach ($file in (Get-ChildItem -File)) {
$file |
Get-Member |
Where-Object {$_.MemberType -eq "Method" -and $_.Definition -like "*system*" } |
Select-Object -Property Name, MemberType
}
$op | Format-List
If I can assign the whole output to a variable, and pipe the variable into another command, why does the following NOT work?
(foreach ($file in (Get-ChildItem -File)) {
$file |
Get-Member |
Where-Object {$_.MemberType -eq "Method" -and $_.Definition -like "*system*" } |
Select-Object -Property Name, MemberType
}) | Format-List
Of course I tried without parents, but ultimately I think if anything, the parents make sense. It is like $file in (Get-ChildItem -File) where it evaluates the expression in the parents and uses the result as the actual object
Is there a way to make this work?
please note that the code is not supposed to achieve anything (else) than giving an example of the mechanics
$(foreach ...), it'll work.$()and(). I've asked questions to this tag in the past, but no one was able to give me a concise answer. I just know wrapping things in a subexpression causes them to output differently.