Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a function from an InlineScript

How can I call a function in a workflow from a nested InlineScript? The following throws an exception because the function is out of scope in the InlineScript:

Workflow test
{
    function func1
    {
        Write-Verbose "test verbose" -verbose
    }

    InlineScript
    {
        func1
    }
}
test
like image 391
David Klempfner Avatar asked Apr 24 '15 03:04

David Klempfner


1 Answers

"The inlinescript activity runs commands in a standard, non-workflow Windows PowerShell session and then returns the output to the workflow."

Read more here.

Each inlinescript is executed in a new PowerShell session, so it has no visibility of any functions defined in the parent workflow. You can pass a variable to workflow using the $Using: statement,

workflow Test
{
    $a = 1

    # Change the value in workflow scope usin $Using: , return the new value.
    $a = InlineScript {$a = $Using:a+1; $a}
    "New value of a = $a"
}   

Test

PS> New value of a = 2

but not a function, or module for that mater.

like image 180
Jan Chrbolka Avatar answered Oct 20 '22 23:10

Jan Chrbolka