Populating Automise variable from Powershell

Hi guys

I'm trying to populate the results from a powershell snippet into an Automise variable using a Run Script action specifying Powershell as the scripting language.

In the OnExecute script section I've got:

   $FBVariables.SetVariable(%vRandom%) = get-random -minimum 99999 -maximum 1000000

which is what I've found in the help topics for this. It fails with bunch of Powershell errors. I've also tried:

  $FBVariables.SetVariable(vRandom) = get-random -minimum 99999 -maximum 1000000

but that also fails with Powershell errors (but different errors from the first try)

I've also tried:

  vRandom = get-random -minimum 99999 -maximum 1000000

as well as

  %vRandom% = get-random -minimum 99999 -maximum 1000000

All fail with various errors.

I assume this is possible and I'm not running it correctly. Anyone care to set me straight? BTW Powershell 3 & Automise 4.0.0.358 is what I have on my Win 7 box.

Thanks

 

David Cook

 

Hi David

I suspect the help is wrong, I will check tomorrow when I get to the office. It may also have worked that way before and is broken. This works for me :

$ATVariables[“AA”] = “hello”

Thanks Vincent, that worked! The help file is definitely wrong about this (probably out of date)

 

For those viewing in the example I gave I had to cast the returned value as string before asigning it to the Automise variable like so:

 

[string]$r = get-random -minimum 99999 -maximum 1000000
$ATVariables["vRandom"] = $r

 

But Vincent's reply was the piece I was missing.

 

Thanks again!

 

 

David

 

 

Hi David

The help is partially correct. The same help file is shared between FinalBuilder and Automise, but the variable collection name is different between the two products. So this works :

$ATVariables.SetVariable(“AA”,“hello world”)

The reason for needing to cast is because powershell cmdlets usually return objects, which can’t be stored in automise variables (which is done via com interop, which doesn’t know how to work with powershell/.net objects).

So I assume you are going to have the help file updated to reflect this? It might also be a good idea to include a couple of examples ... and also include the casting stuff.

 

Thanks

 

David

Hello. I just searched the most recent automise help file and I see that the help file has not been updated. It still refers to $FBVariables.SetVariable() on page 59.

Also, I see there is also an Execute Powershell Script Action (pp 726). Can this action also pass variables back via the $ATVariables.SetVariable commands, or just the scripting tool?

The pdf’s are out of date, I guess we should remove them till we figure out how to create new ones (using confluence now).

https://wiki.finalbuilder.com/display/AT5/

The Execute Powershell script action executes an external instance of powershell, so it can’t set Automise varibales. Use the Run Script action, in the script editor set the language to Powershell. This executes the script in process and can interact with Automise. using

$ATVariables.SetVariable("variablename", "value")

You can also use this syntax

$ATVariables["variablename"] = "value"