4

I'm trying to pass a user supplied value into PowerShell script using the following code, but am having no luck:

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

The argument writes in the PowerShell command line, but it is not passing the variable into the .ps1 script with this syntax $MyVar.

James A Mohler
  • 10,562
  • 14
  • 41
  • 65
  • As an aside, there is no need to wrap `` tag in ``. The CF variables inside the tag will be evaluated automatically. – Leigh Nov 27 '16 at 18:52

2 Answers2

1

try it

<cfexecute name="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments="-file C:\Users\raimonds\Desktop\create_website_IIS_aws_uat_1.ps1 ""youvalue"""/>
Esperento57
  • 13,361
  • 2
  • 30
  • 35
1

Your were almost there. Just change the order, as follows:

<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#'" />

Alternatively, define the arguments attribute as

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

This assumes your script defines the parameter MyVar in the usual way, for example:

 param([string]$MyVar)

See this Stackoverflow page for additional Powershell options you might want to use.

Community
  • 1
  • 1
BKBK
  • 474
  • 2
  • 9