Author Posts

November 10, 2013 at 11:46 pm

is the only way to pass variables to function is like this :

function test {
params([string]$arg1)
Write-Host $arg1;
}
i understand i can't call
test "dddd"+"eeeee"
but only
$str="dddd"+"eeeee"
test $str

isn't there another way to concat parms on the line i call the function?

November 11, 2013 at 2:49 am

Your code has a type – it should be param not params

Its not the only way but I think its the best especially when you start to look at advanced functions

you could do

test ("dddd"+"eeeee")

November 11, 2013 at 5:04 am

Yep, put parentheses around the expression to force PowerShell into Expression mode parsing, instead of Argument mode. See the about_Parsing help file for all the details on this.