【问题标题】:running a PowerShell script with parameters from a batch script使用批处理脚本中的参数运行 PowerShell 脚本
【发布时间】:2015-07-06 23:59:50
【问题描述】:

我正在编写一个批处理脚本来读取一些参数并启动一个 PowerShell 脚本,该脚本需要输入的参数。

到目前为止我做了什么:

Set /p arg1 = Type in a name for the  data: 

Set /p arg2 = Type in the directory of the project: 

Set /p arg3 = Type in the programming language : 

Set /p arg4 = Type in a version for the metric data: 

SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%Metrics.ps1

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' 'arg1' 'arg2' 'arg3' 'arg4'";

很遗憾,PowerShell 脚本不接受参数。

【问题讨论】:

  • SO 已经回答了这个问题。我真的会关注@deadlydog 的链接。他的blog很好。
  • 谢谢,我会记住的

标签: powershell batch-file


【解决方案1】:
PowerShell -NoProfile -ExecutionPolicy Bypass -file "%PowerShellScriptPath%" %arg1% %arg2% ....

【讨论】:

    【解决方案2】:

    您的变量名称有一个尾随空格(“whatever”)。等号前后去掉空格:

    Set /p arg1=Type in a name for the  data: 
    Set /p arg2=Type in the directory of the project: 
    Set /p arg3=Type in the programming language : 
    Set /p arg4=Type in a version for the metric data: 
    

    【讨论】:

    • 现在几乎没有我的答案?
    猜你喜欢
    • 2013-07-30
    • 2015-01-03
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    相关资源
    最近更新 更多