【发布时间】:2010-12-20 18:10:38
【问题描述】:
我有一个批处理文件 test.bat 来启动一个 powershell 脚本:
@pushd "C:\myscripts"
powershell .\test.ps1 arg1 "arg2 with space" arg3
@popd
脚本 test.ps1(位于 C:\myscripts)是一个非常简单的脚本,例如:
# just print out the arguments
Write-Output ("args count: {0}" -f $args.length)
$args
然后我尝试启动 test.bat。我应该将三个参数传递给 ps1 但我得到了以下结果:
参数数:5 参数1 arg2 和 空间 arg3
我在脚本中所期望的,args[0] 应该是 arg1,args[1] 应该是“arg2 with space”,而 args3[2] 应该是 arg3。我不明白为什么脚本实际上有 5 个参数。
如何按预期将参数从 cmd 或批处理传递到 powershell?像这样:
args count: 3
arg1
arg2 with space
arg3
【问题讨论】:
标签: powershell