PowerShell function parameters syntax

后端 未结 1 1705
借酒劲吻你
借酒劲吻你 2021-01-18 22:36

Why do the Write-Host outside of the function work different than inside of the function?

It seems like somehow the parameters variables are changing from what I dec

相关标签:
1条回答
  • 2021-01-18 23:08

    Don't call functions or cmdlets in PowerShell with parentheses and commas (only do this in method calls)!

    When you call a($svr, $usr) you're passing an array with the two values as the single value of the first parameter. It's equivalent to calling it like a -svr $svr,$usr which means the $usr parameter is not specified at all. So now $x equals the string representation of the array (a join with spaces), followed by a backslash, followed by nothing.

    Instead call it like this:

    a $svr $usr
    a -svr $svr -usr $usr
    
    0 讨论(0)
提交回复
热议问题