How to enable Out-GridView in a function.
I mean,
"Hello" | Out-GridView
Works.
But if I have a simple function like this
function Count ([int]$times)
{
for ($i=1; $i -le $times;$i++)
{
Write-Host $i
}
}
Why calling Count 5 doest not support a pipe to Out-GridView?
The problem you are having is that
Write-Hostdoes not output to the pipeline at all. It writes directly to the screen. ReplaceWrite-HostwithWrite-Outputand it should work fine.BTW,
Write-Outputis the default so you could just use:or even more simply: