Is is possible within a workflow, to run a command which runs a PowerShell script, and have a variable generated by this PS script returned to the Workflow to be used in the next command?
I have a script which update an Oracle database, a unique identifier is created which I would like to use later in the workflow.
Any guidance appreciated.
WFA commands are also PoSH scripts, so if one PoSH script can call another, WFA commands too can do it.
Perhaps this can do it: Use this line in your WFA command code
$var2 = Invoke-Expression <path_to_script_1>
or $var2 = Invoke-Expression <path_to_script_1> <param_list>
Google more on this and lots of info are available.
@ I have a script which update an Oracle database, a unique identifier is created which I would like to use later in the workflow.
If the unique identifier is returned by first script, the the calling script( i.e. WFA command ) can sure obtain this.
But do you want 2 scripts? Maybe You can copy the contents of script1 in WFA command itself. Just thinking of some possibilities but it perhaps depends on you code.
No, this is not possible. When executing a workflow, WFA first goes through a planning phase. In this phase, all parameters in your workflow are resolved, all queries against the cache database are executed etc. Once planning is finished, all input parameters for all commands are "fixed" and you can't change them in the actual execution phase of the workflow.
Therefore WFA command have input parameters but can't return anything back into the workflow. You either need to combine both commands into one large command or use ways to store the information outside of WFA (write it to a temporary file or so). Passing information between commands behind WFAs back is a dirty workaround though and you should avoid it if at all possible.
Of course it is possible and its not any workaround and certainly not dirty.
To show it, I'm attaching a PowerShell script and a workflow which can be imported on WFA2.1. The Script random.ps1 generates a random number only upon execution and returns it to its caller. Our WFA command "Get a Random Parameter" will try to execute this PoSH script and catch the run-time value generated by it.
I think you misunderstood the question. Of course you can do whatever you want within a command and this includes calls to external scripts. However, you can't pass information from a command back into the workflow and from there on to the next command. To quote the original question:
" [...] have a variable generated by this PS script returned to the Workflow to be used in the next command"
A WFA command can't return anything back into the workflow and you can't generate something in a command that is then available in the next command. The reason for this is the WFA concept of having a planning phase in which all parameters are evaluated as I explained in my previous post.
You could work around this by writing information into a file when executing command1 and then read that information when executing command2. It would work but bypasses a fundamental concept of WFA and therefore is a dirty workaround.
Ahh.. I don't know Hendrik... but I'm going with what is the intent of user than looking at exact wordings. I accept that WFA as of 2.1 can't return an run-time generated value back to the next workflow command, but I don't think that's not what is desired here. I see user says that generation of unique identifier is not done by any WFA command but by another external Powershell script. WFA command wants to invoke the execution of this script and obtain the identifier returned.
So why will I Invoke my external posh script in cmd1 and then try to obtain the identifier it generated in cmd2. Why not invoke the script in cmd2 itself and obtain the identifier.