passing varaibles to function

This topic contains 3 replies, has 3 voices, and was last updated by  Dave Wyatt 4 years, 8 months ago.

  • Author
  • #11344

    wantto wantto

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

    function test {
    Write-Host $arg1;
    i understand i can't call
    test "dddd"+"eeeee"
    but only
    test $str

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

  • #11348

    Richard Siddaway

    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")

  • #11349

    wantto wantto


  • #11350

    Dave Wyatt

    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.

You must be logged in to reply to this topic.