I'm trying to create a PowerShell script for retrieving JSON data from a Rest API. This script would run as a SQL Server Agent Job, and insert the final data table with everything collected into the database.
I've explored -Parallel option for the Foreach loop, added it to a workflow, but get blocked when trying to write data to the datatable because it seems to be treated differently than just a simple object.
Is this something that could be done with jobs? Is there another way I could run this in parallel? Does the whole thing need restructured? Ideally this would run in just native PowerShell code without having to install any other modules.
The basic structure of my code today is:
#Compose URL
#Create a New-Object system.Data.DataTable and configure it
#Make Invoke-RestMethod API call to get the collection of objects
Foreach($object in $Collection){
#Make API call for details about each object
#Add data to datatable
}
#Write datatable to database