# Set Conrinua Variable by external script

**URL:** <https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476>\
**Category:** Discussion\
**Created:** [May 2, 2016, 10:51am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476 "2016-05-02T10:51:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergeykagan](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@sergeykagan](https://www.finalbuilder.com/forums/u/sergeykagan)\
**Post date:** [May 2, 2016, 10:51am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476/1 "2016-05-02T10:51:33Z")

</div>

Hi  
I know I can setup Continua Variable from FinalBuilder there is such action in FB 7.&nbsp;  
Is there way to do it from power shell script or other external way?  
Thanks

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [May 3, 2016, 1:38am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476/2 "2016-05-03T01:38:50Z")

</div>

Hi Sergey,  
  
You can set Continua CI variables from PowerShell scripts, batch files or other external programs by writing&nbsp;[custom log messages](http://wiki.finalbuilder.com/display/continua/Custom+Log+Messages) to the console.&nbsp;e.g.&nbsp;

`$message = ``"Continua CI is awesome!"`

`write-Host ``“@@continua[setVariable name=‘messageFromScript’ value=’$message’]”`

---

<div class="post-metadata">

**Author:** ![lesergeur](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/l/9d8465/32.png) [@lesergeur](https://www.finalbuilder.com/forums/u/lesergeur)\
**Post date:** [August 5, 2016, 8:29am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476/3 "2016-08-05T08:29:44Z")

</div>

Hello,   
  
 I am struggling with setting up a variable in this way (sort of). I want to just run a PowerShell command in my stage without creating script files. I have other commands that succeed if I simply invoke them in a Run DOS command action, like such:   
  
 PowerShell -command (get-item MyAssembly.dll).versioninfo.fileversion   
  
 So I’m trying to set a variable in the same way:   
  
 PowerShell -command {write-Host “@@continua[setVariable name=‘PlatformVersion’ value=‘1.2’]”}   
 PowerShell -command (write-Host “@@continua[setVariable name=‘PlatformVersion’ value=‘1.2’]”)   
 PowerShell -command write-Host “@@continua[setVariable name=‘PlatformVersion’ value=‘1.2’]”   
  
 I’ve tried all of the above but they all return the same errors:   
  
 At line:1 char:13   
 + (write-Host @@continua[setVariable name=‘PlatformVersion’ value=‘1.2’])   
 + ~   
 Unrecognized token in source text.   
 At line:1 char:24   
 + (write-Host @@continua[setVariable name=‘PlatformVersion’ value=‘1.2’])   
 + ~   
 Array index expression is missing or not valid.   
 At line:1 char:14   
 + (write-Host @@continua[setVariable name=‘PlatformVersion’ value=‘1.2’])   
 + ~~~~~~~~~   
 The splatting operator ‘@’ cannot be used to reference variables in an   
 expression. ‘@continua’ can be used only as an argument to a command. To   
 reference variables in an expression use ‘$continua’.   
 + CategoryInfo : ParserError: ( I know that I’m probably making a simple mistake, but I will need your help to figure it out. Thank you.

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [August 8, 2016, 3:38am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476/4 "2016-08-08T03:38:40Z")

</div>

Hi&nbsp;Lesergeur,  
  
You can use [the “& {}” syntax](https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help#command)&nbsp;as follows&nbsp;

`PowerShell -command "& {write-Host “@@continua[setVariable name=‘PlatformVersion’ value=‘1.2’]”}"`

  
Note the use of backslashes to escape double quotes.  
  
You don’t however need to use PowerShell at all here - as you are using a DOS Command action you can simply use the DOS command “echo” to write out the [custom log message](http://wiki.finalbuilder.com/display/continua/Custom+Log+Messages).  
  

`echo @@continua[setVariable name=‘PlatformVersion’ value=‘1.2’]`

  
Furthermore, Continua CI has a Set Variable action - why not just use this?&nbsp;

---

<div class="post-metadata">

**Author:** ![lesergeur](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/l/9d8465/32.png) [@lesergeur](https://www.finalbuilder.com/forums/u/lesergeur)\
**Post date:** [August 9, 2016, 8:55am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476/5 "2016-08-09T08:55:43Z")

</div>

Hello Dave,   
  
 My actual intention is to set a variable to a value that I can best obtain from a PowerShell command. My example above was only to help me resolve a basic PowerShell error. (I did have a hunch from the error that something was amiss with the quote, but did not realize it needed to be escaped.)   
  
 My final command turns out to be this: \<

```auto
PowerShell -command "& {write-Host \"@@continua[setVariable name='PlatformVersion' value='$((get-item MyAssembly.dll).versioninfo.productversion)']\"}"

```

It works. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![lesergeur](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/l/9d8465/32.png) [@lesergeur](https://www.finalbuilder.com/forums/u/lesergeur)\
**Post date:** [August 9, 2016, 8:57am UTC](https://www.finalbuilder.com/forums/t/set-conrinua-variable-by-external-script/5476/6 "2016-08-09T08:57:39Z")

</div>

Let me try that again…

```auto
PowerShell -command "& {write-Host \"@@continua[setVariable name='PlatformVersion' value='$((get-item MyAssembly.dll).versioninfo.productversion)']\"}"

```
