0

I have a function

function Build-Exec($path,$param1,$param2,$param3,$param4)
{
    $var = @($path,$param1,$param2,$param3,$param4) -join " "  
    return $var 
}

when i call it it returns

System.Object[]  

How can i make it return a string?

example usage

$var1 = Build-Exec("1","2","3","4","5") 

Write-Output $var1
1
  • Cannot reproduce. Maybe the variable names are mistyped, but since the sample doesn't have actual usage, it's just a guess. Commented May 29, 2020 at 11:41

1 Answer 1

1

The problem is that isn't how you define or call parameters for a function in PowerShell

function Build-Exec
{
    Param ($path,$param1,$param2,$param3,$param4)
    $var = @($path,$param1,$param2,$param3,$param4) -join " "  
    return $var 
}

Calling the function

$var1 = Build-Exec "1" "2" "3" "4" "5"
Write-Output $var1
1 2 3 4 5

When you include the commas, you are passing the first param a string array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.