Understanding Multiple Return Values

by May 4, 2016

PowerShell has an unusual way of dealing with return values. Anything you left behind will be added to the return values. The statement "return" does not exclusively define a return value. This is why the following function has multiple return values, and not just the value defined by "return" keyword:

function Do-Something
{
    param($Text)


    Get-Date
    $sapi = New-Object -ComObject sapi.spvoice
    $sapi.Speak($Text)
    $Text = 12
    "Text = $Text"
    
    return 'this is NOT THE ONLY return value now!'
}

Do-Something -Text "Hello"

Twitter This Tip! ReTweet this Tip!