All three of these methods display the results in similar manners. My question is why in METHOD 01, I can't use Write-Output {$_.FullName}, instead, I have to use a ForEach-Object?
I have to use METHOD 01 to run it against a function that I created.
Clear-Host
#METHOD 01
Get-ChildItem -Path 'D:\' -Directory -Depth 0 |
ForEach-Object{$_.FullName} |
Sort-Object
#METHOD 02 (Sticking into Variable)
$AA = Get-ChildItem -Path 'D:\' -Directory -Depth 0
Write-Output $AA.FullName |
Sort-Object
#METHOD 03 (Sticking into Variable)
$AA = Get-ChildItem -Path 'D:\' -Directory -Depth 0
ForEach($oItem in $AA)
{
$oItem.FullName
}
Get-ChildItem | Write-Output -InputObject { $_.FullName }, which resolves the ambiguity between pipeline input and argument.Filter MyFunction { $_ }. This would be a "do nothing" filter. For more complex stuff create an advanced function with a parameter that accepts pipeline input ([Parameter(ValueFromPipeline)] $InputObject).