2016-11-26 196 views
3

我嘗試使用下面的代碼通過用戶提供的價值爲PowerShell腳本,但我有沒有運氣:如何通過CFExecute參數將變量傳遞到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

+0

順便說一句,沒有必要在''中包裝''標籤。標籤內的CF變量將被自動評估。 – Leigh

回答

0

嘗試

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

非常奇怪,但第二個答案是正確的雙引號。非常感謝 ! –

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="& 'C:\Users\raimonds\Desktop\create_website_IIS_aws_uat_1.ps1' 
    MyVar '#MyVar#'" 

這裏假設你的腳本定義通常的方式參數MyVar的,例如:

param([string]$MyVar) 

看到這個Stackoverflow page for additional Powershell options你可能想要使用。

相關問題