4

我正在尝试使用以下代码将用户提供的值传递给 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 命令行,但它没有使用此语法将变量传递到 .ps1 脚本$MyVar

4

2 回答 2

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"""/>
于 2016-11-26T09:31:45.860 回答
1

你几乎就在那里。只需更改顺序,如下:

<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)

有关您可能想要使用的其他 Powershell 选项,请参阅此Stackoverflow 页面。

于 2016-11-27T13:20:02.763 回答