簡體   English   中英

如何通過CFExecute參數將變量傳遞給powershell腳本?

[英]How to pass variable into powershell script through CFExecute arguments?

我正在嘗試使用以下代碼將用戶提供的值傳遞到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腳本。

你幾乎就在那里。 只需更改順序,如下所示:

<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頁面

試試吧

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM