0

Usually, I use dot-sourcing to "import" my function defined in other script files.

But the Powershell Workflow does not allow dot-sourcing, and it can't recognize functions defined out of scope.

Is there any possible way instead of copy-pasting all the functions into the Workflow to invoke them?

For example:

# another_script.ps1

function FuncToBeCall {
  # do something
}
# main.ps1

# Usual way I import the functions
. $PSScriptRoot\another.script.ps1

# I can invoke function here normally
FuncToBeCall

Workflow RunSomething
{

  # do something...

  # Want to invoke here, or in InlineScript/Sequence/Parallel
  FuncToBeCall

}

RunSomething

PS. The reason I try to do it in the Workflow way is to take advantage of the Parallel. Otherwise, I might do this in a normal way. Just looking for the best practice.

3
  • change another_script.ps1 to psm1 and then you can call it with import-module learn.microsoft.com/en-us/powershell/module/… Commented Nov 11, 2021 at 14:31
  • Parallel workflow is nowhere near as fast as a linear loop and not even close to runspace. What I mean by this is that if you're looking for multi-threading options on PowerShell you should focus on Runspace or ThreadJob Module from Microsoft. Commented Nov 11, 2021 at 14:51
  • Or ForEach-Object -Parallel { ... } if you are running PS Core. Commented Nov 11, 2021 at 14:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.