@Christianに同意し、別のソリューションを追加します。
まず、明示的または暗黙的に配列を使用して戻ることができます。
A)明示的に
function ExplicitArray ()
{
$myArray = @()
$myArray += 12
$myArray += "Blue"
return ,$myArray
}
Clear-Host
$a = ExplicitArray
Write-Host "values from ExplicitArray are $($a[0]) and $($a[1])"
B)暗黙的に
function ImplicitArray ()
{
Write-Output 12
Write-Output "Blue"
return "green"
}
$b = ImplicitArray
Write-Host "values from ImplicitArray are $($b[0]), $($b[1]) and $($b[2])"
次に、カスタムオブジェクトを返すことができます。
A)短縮形
function ReturnObject ()
{
$value = "" | Select-Object -Property number,color
$value.Number = 12
$value.color = "blue"
return $value
}
$c = ReturnObject
Write-Host "values from ReturnObject are $($c.number) and $($c.color)"
B)学校形態
function SchoolReturnObject ()
{
$value = New-Object PsObject -Property @{color="blue" ; number="12"}
Add-Member -InputObject $value –MemberType NoteProperty –Name "Verb" –value "eat"
return $value
}
$d = SchoolReturnObject
Write-Host "values from SchoolReturnObject are $($d.number), $($d.color) and $($d.Verb)"
3番目に参照による引数の使用
function addition ([int]$x, [int]$y, [ref]$R)
{
$Res = $x + $y
$R.value = $Res
}
$O1 = 1
$O2 = 2
$O3 = 0
addition $O1 $O2 ([ref]$O3)
Write-Host "values from addition $o1 and $o2 is $o3"