Recently, I\'ve been playing with PowerShell, and I\'ve noticed some weird behavior when using pipes and foreach loops that I couldn\'t understand.
foreach
This
You need to evaluate the foreach before piping the resulting Object like you did in the first test:
$(foreach ($i in gci){$i.length}) | measure -max
Alternatively, use the % shorthand to which will evaluate it before piping it as well:
%
gci | % { $_.Length } | measure -max