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.

David Lee
  • 1
  • 1
  • change ```another_script.ps1``` to ```psm1``` and then you can call it with ```import-module``` https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7.2 – dcaz Nov 11 '21 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. – Santiago Squarzon Nov 11 '21 at 14:51
  • Or `ForEach-Object -Parallel { ... }` if you are running PS Core. – Santiago Squarzon Nov 11 '21 at 14:58

0 Answers0