Just try the following:
function test
{
$strArr = @("aaa", "bbb", "ccc")
$stringBuilder = New-Object System.Text.StringBuilder
foreach ($item in $strArr)
{
$stringBuilder.AppendLine($item) | Out-Null
}
$out = $stringBuilder.ToString()
write-host "FIRST OUT: ", $out, "OUTTYPE:", $out.GetType()
return $out
}
$out2 = test
Write-Host "-------------------"
write-host "SECOND OUT2: ", $out2, "OUT2TYPE:", $out2.GetType()
The explanation is that it $stringBuilder.AppendLine()outputs something and is added to the output of the function.
:
, . , PowerShell - return keywork ($ out), , ( ). about_Return, ,
Windows PowerShell , , Return.