【问题标题】:How to pass variable into powershell script through CFExecute arguments?如何通过 CFExecute 参数将变量传递给 powershell 脚本?
【发布时间】:2016-11-26 01:04:47
【问题描述】:

我正在尝试使用以下代码将用户提供的值传递给 PowerShell 脚本,但没有运气:

<cfset MyVar="Woila!">

<cfoutput>
<cfexecute name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" 

arguments="$MyVar = #MyVar# C:\Users\raimonds\Desktop\create_website_IIS_aws_uat_1.ps1" 
/>
</cfoutput>

参数写入 PowerShell 命令行,但它没有将变量传递到具有此语法 $MyVar 的 .ps1 脚本中。

【问题讨论】:

  • 顺便说一句,没有必要将&lt;cfexecute&gt; 标签包裹在&lt;cfoutput&gt; 中。标签内的 CF 变量将被自动评估。

标签: powershell iis coldfusion cfexecute


【解决方案1】:

试试看

<cfexecute name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments="-file C:\Users\raimonds\Desktop\create_website_IIS_aws_uat_1.ps1 ""youvalue"""/>

【讨论】:

  • 很奇怪,但第二个答案用双引号是正确的。非常感谢!
【解决方案2】:

你就快到了。换个顺序就好了,如下:

<cfset MyVar="Woila!">

<cfexecute name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" 

arguments="C:\Users\raimonds\Desktop\create_website_IIS_aws_uat_1.ps1 
 MyVar '#MyVar#'" />

或者,将 arguments 属性定义为

arguments="& 'C:\Users\raimonds\Desktop\create_website_IIS_aws_uat_1.ps1' 
     MyVar '#MyVar#'"

这假设您的脚本以通常的方式定义参数 MyVar,例如:

 param([string]$MyVar)

请参阅您可能想要使用的Stackoverflow page for additional Powershell options

【讨论】:

    猜你喜欢
    • 2013-05-01
    • 2011-08-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多