我想在powershell中输出函数的参数,但是它会在一行中显示参数的结果,因此$ VariableHere2无法正确显示。我如何只捕获$ 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)
答案 0 :(得分:1)
调用函数时不要使用'()'而不要使用逗号','。 '(stuff here)'是新代码或数据的标记,应在请求之前收集或一起运行。正确的方法是....
Get-Something $VariableHere $VariableHere2
OR
Get-Something -VariableHere $VariableHere -VariableHere2 $VariableHere2