Magic of Foreach-Object.

It’s Sunday morning and I should probably do something else than playing with PowerShell. But Chad Miller and Oisin Grehan made me dig more into way Foreach-Object behaves. I was always sure that construct like that:

1..10 | ForEach-Object { '=' * 80 } { $_ } { '-' * 80 }

work because documentation is wrong about the way –Begin and –End behave. Oisin comment forced me to actually check it… And because there is no better way to check how things actually  work than by using Trace-Command cmdlet – I did so. And it proven Oisin (and documentation) to be right about parameters binding rules:

Read more…