powershell - 使用括号调用函数时 Powershell 中的参数合并

标签 powershell

我试图将两个参数传递给 PowerShell 中的函数,但发现了奇怪的结果。当我将参数传递到函数中并将它们输出到组合字符串中时,所有参数都显示在第一个参数的位置。

这是我的代码:

$s = "D:\"
$o = "I:\"

function a($source, $output){
    Write-Output $source
    Write-Output $output
    Write-Output "exe $source --parameter $output"
}


Write-Output $s
Write-Output $o
Write-Output "exe $s --parameter $o"

a($s, $o)

输出:

D:\
I:\
exe D:\ --parameter I:\
D:\
I:\
exe D:\ I:\ --parameter

Notice "I:\" is in a different place

我想调用该函数并获得以下输出:

D:\
I:\
exe D:\ --parameter I:\

谁能帮我解决如何避免这种情况?

最佳答案

我刚刚发现,如果我调用不带括号和逗号的函数,它就会按照我想要的方式工作。

a $s $o

输出:

D:\
I:\
exe D:\ --parameter I:\

关于powershell - 使用括号调用函数时 Powershell 中的参数合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46276244/

相关文章:

powershell - powershell 脚本中的更正

sql - 在 psql.exe 中插入失败(从 powershell 创建)

regex - PowerShell 在匹配后检索 3 个字符

windows - 使用 powershell 在 IIS 10 中重新绑定(bind)证书

sharepoint - SharePoint 2010-添加具有工作流程批准状态和PowerShell的列表项

powershell - vscode命令行: open a file of an opened project

powershell - 没有 CurrencyGroupSeparator 的舍入

regex - 在 Powershell 中使用函数替换

powershell - 将Get-Childitem过滤为CSV的内容

.net - 在 Windows 8 RTM 上的 .NET 应用程序中嵌入 Powershell v2.0