Returning Multiple Values

by Sep 10, 2013

A PowerShell function can return multiple values. To receive them, simply assign the result to multiple variables:

function Get-DateTimeInfo
{
    # Value 1
    Get-Date -Format 'dddd'

    # Value 2
    Get-Date -Format 'MMMM'

    # Value 3
    Get-Date -Format 'HH:mm:ss'
}

$day, $month, $time = Get-DateTimeInfo

"Today is $day, the month is $month, and it is $time" 

Twitter This Tip! ReTweet this Tip!