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
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With