Boolean variable gets returned as an Object[]
As @mjolinor said, you need to show the rest of your code. I suspect it's generating output on the success output stream somewhere. PowerShell functions return all output on that stream, not just the argument of the return
keyword. From the documentation:
In PowerShell, the results of each statement are returned as output, even without a statement that contains the Return keyword. Languages like C or C# return only the value or values that are specified by the
return
keyword.
There's no difference between
function Foo { 'foo'}
or
function Foo { 'foo' return}
or
function Foo { return 'foo'}
Each of the above functions returns the string foo
when called.
Additional output causes the returned value to be an array, e.g.:
function Foo { $v = 'bar' Write-Output 'foo' return $v}
This function returns an array 'foo', 'bar'
.
You can suppress undesired output by redirecting it to $null
:
function Foo { $v = 'bar' Write-Output 'foo' | Out-Null Write-Output 'foo' >$null return $v}
or by capturing it in a variable:
function Foo { $v = 'bar' $captured = Write-Output 'foo' return $v}
return something ## is not the only thing that PowerShell returns. This is one of the gotchas of PowerShell, if you will. All output on the success output stream will also be returned. that's why you have an array of objects returning from your function.
function test { "hello" return "world"}$mytest=test$mytest
try the code above... you will not get just "world" but "hello""world"
$mytest.count2