0

I have a PS1 file with Invoke-RestMethod on 10 different urls. I want to make them execute in parallel and get the data from them. All the examples I've seen are for running scripts in parallel.

How can I execute:

$dataA = Invoke-RestMethod -Uri 'https://xyz/A' -WebSession $WebSession -Method Post -Body $queryA
.
.
.
$dataK = Invoke-RestMethod -Uri 'https://xyz/K' -WebSession $WebSession -Method Post -Body $queryK

The above code in parallel, such that I could use the data in dataA to dataK outside the parallel block.

Thanks

asked Sep 7, 2020 at 9:05

2 Answers 2

1

You can use Powershell Workflow.

workflow paralleltest {
 
 parallel {
 
 $dataA = Invoke-RestMethod -Uri 'https://xyz/A' -WebSession $WebSession -Method Post -Body $queryA
 $dataK = Invoke-RestMethod -Uri 'https://xyz/K' -WebSession $WebSession -Method Post -Body $queryK
 
 }
 }
answered Sep 7, 2020 at 9:34
Sign up to request clarification or add additional context in comments.

Comments

0

You could use the cmdlet "ForEach-Object" with the parameter "-Parallel" explained here: PowerShell ForEach-Object Parallel Feature

Although, I havent done it before, I would suggest the following:

  1. Define your variables $dataA..$dataZ

2.$dataA..$dataZ|ForEach-Object...-parallel

answered Sep 7, 2020 at 9:21

2 Comments

Tat is for running the same command multiple times right?
Well...the command "invoke..." is the same but the rest is ofc different.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.