In PowerShell, say I have a collection of string objects:
'a b c'.split()
I can pipe these to an output stream:
'a b c'.split() | Write-Host
So I get "a", "b" and "c" on separate lines.
Now: how do I change this so that each line (string) has a leading tab character?
I know tab is represented by `t so my first attempt was this:
'a b c'.split() | Write-Host "`t$_"
This gives me the error:
Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
Okay, so let's take out the tab and just use $_ which I thought represented the 'current' object that was being returned by the pipeline.
'a b c'.split() | Write-Host $_
Same error:
Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
There is obviously something I'm fundamentally misunderstanding here, so I'm hoping someone can point out what that is! Also, ignore the use of Write-Host: I'm just using it for illustration purposes, my intention is to pipe to Write-Verbose ultimately.
$_variable is create by certain cmdlets, it doesn't just exist by default when passing things down the pipeline. That's why usingfor-eachworks. Thefor-eachcmdlet create the$_variable and then invokes your script/expression. - Sean