What I have found is that when I write the following function:
function test {
Write-Host ($input | Measure-Object).Count
Write-Host ($input | Measure-Object).Count
}
with sample input:
dir | test
it writes on the console:
18
0
I think it is because the first pipe to Measure-Object overwrites $input. I know of a workaround where I would make a new array and pass that around:
function test {
$inp = @($input)
Write-Host ($inp | Measure-Object).Count
Write-Host ($inp | Measure-Object).Count
}
However I don't like it because I am introducing a new variable. Is there a way of piping to a cmdlet while leaving $input unaffected?