0

I've the following code to execute parallels command in powershell

workflow Test-Workflow {
    
    $Sites = "Param1", "Param2", "Param3"
    
    ForEach -Parallel ($site in $Sites) {
        Parallel {
            InlineScript { C:\MyScriptsFolder\Script.ps1 -siteName $using:Sites}
        }
    }
}

Test-Workflow

I would like to execute my script with a relative path, instead of full path. But If I try to execute as

InlineScript { ..\Script.ps1 -siteName $using:Sites}

I got the error

e term ..\Script.ps1 is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

How can I use relative paths with InlineScript?

Thanks

5
  • The dots should be separated . .\Script.ps1 if you want to dot source your script. Otherwise if you to just execute it use only 1 dot Commented Oct 21, 2022 at 12:25
  • As aside using relative paths is prone to failure. And workflow is usually not the best multithreading alternative available in PoweShell Commented Oct 21, 2022 at 12:28
  • Which other alternative can I use? Thanks! Commented Oct 21, 2022 at 12:30
  • For execution in parallel threads, use Start-ThreadJob in Windows PowerShell (requires Install-Module ThreadJob), and ForEach-Object -Parallel in PowerShell (Core) 7+ Commented Oct 21, 2022 at 12:35
  • If you're on Windows PowerShell and can't install the module, you can get parallel threads via multiple runspaces using the PowerShell SDK, but that's significantly more complex. Note that workflows are obsolescent, as evidenced by the fact that they weren't included in PowerShell (Core) 7+ Commented Oct 21, 2022 at 12:37

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.