【发布时间】:2018-02-20 04:24:40
【问题描述】:
This question 和 this blog post 解决了如何将特定参数从批处理文件传递到 PowerShell 脚本。
如何将所有参数传递到 PowerShell 脚本中?基本上我想 splat 所有参数,以便批处理文件透明地传递所有参数。
编辑以获得更多上下文:
我目前正在使用这样的一行:
PowerShell.exe -Command "& '%~dpn0.ps1' '%1' '%2'"
这可行,但会在文件之间创建冗余,因此,如果我更新 PowerShell 脚本以采用不同的参数,我也必须更新批处理脚本。如果我能做这样的事情就好了:
PowerShell.exe -Command "& '%~dpn0.ps1' '%*'"
【问题讨论】:
-
你能提供一个你想要的例子吗?
Cmd没有像PSv3+ 那样飞溅。 -
@TheIncorrigible1 我目前使用像
PowerShell.exe -Command "& '%~dpn0.ps1' '%1' '%2'"这样的行;我希望能够传递所有参数而不必枚举它们。 -
我不确定这是否可行或如何,但最好能像
PowerShell.exe -Command "& '%~dpn0.ps1' '%*'"
标签: windows powershell batch-file