Call a function from an InlineScript Call a function from an InlineScript powershell powershell

Call a function from an InlineScript


"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"}   TestPS> New value of a = 2

but not a function, or module for that mater.


In the past I used the technique where I put all the common stuff in powershell module file, and do:

workflow Hey{   PrepareMachine   ConfigureIIS}function PrepareMachine() {  Import-Module "MyCommonStuff"  CallSomethingBlahBlah()}function ConfigureIIS {  Import-Module "MyCommonStuff"  CallSomethingBlahBlah2()}

You don't even have to wrap it in a module, you could just define the function out of workflow, and it would still work:

workflow Hey {   InlineScript {     func1  }}function func1 {  Write-Output "Boom!"}

That said, I was not impressed by workflows at all. Seems like quite pointless feature if you ask me. The most useful stuff about workflows is the ability to run things in parallel, but jobs can do it too. The idea above rant is that make sure you really do need workflows :)