simple question about variable in function

by Jun 4, 2013


example function :

Function Add ($x, $y)


$Ans = $x + $y

Write-Host “The Answer is $Ans”


this function sum $x and $y and put the result in $Ans.

to run the function i will write:

Add 8 2

the output will be: " The Answer is 10"

now, I want to put this answer in anther variable(outside the function):

$d=Add 8 2


when I run those two lines I get that $d is empty.

so, how can I put function answer in variable outside the function?