0

I want to output the parameters of a function in powershell, but it is displayed the result of the parameters in one single line, so the $VariableHere2 cannot be displayed properly. How do I catch only the $VariableHere2 ?

Function Get-Something {
Param([string]$VariableHere,[string]$VariableHere2)
Write-Output "My variable 1 is $VariableHere"
Write-Output "My variable 2 is $VariableHere2"}

$VariableHere = "test1"
$VariableHere2 = "test2"
Get-Something($VariableHere,$VariableHere2) 
1
  • 3
    You committed the #1 mistake new PowerShell developers make: commas. Invoke the function as Get-Something $VariableHere $VariableHere2, otherwise you're passing an array of two values as one single parameter. Commented Oct 2, 2017 at 15:09

1 Answer 1

1

when calling the function dont use '()' and dont use commas ',' . '(stuff here)' is a mark of new code or data that should be gathered or Run together before the request. The correct way would be....

Get-Something $VariableHere $VariableHere2

OR

Get-Something -VariableHere $VariableHere -VariableHere2 $VariableHere2
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.