I'm wondering what the optimal (speed-wise) way is to accomplish this? This is the current script I have going, but it takes hours, probably because of the nested FOR loop, and start-sleep for API request limitations. Suggestions or changes? I'm all ears on how to improve this.
$token = Invoke-RestMethod -Uri https://<uri path> -Body $body -Method Post -UseBasicParsing
$header = @{Authorization='Bearer '+$token.access_token}
$dataGroup1 = Invoke-RestMethod -Header $header -Uri https://<pathname> -UseBasicParsing
$add = For ($i=0;$i -le $dataGroup1 .data.Count-1; $i++) { $prodDate = (Get- Date).AddDays(-3).ToString("yyyy-MM-dd")
$header = @{Authorization='Bearer '+$token.access_token}
$uri = "<url path>" + $dataGroup1.data[$i].id + "/readings?" + $prodDate
$readings = Invoke-RestMethod -Header $header -Uri $uri -UseBasicParsing
For ($f=0;$f -le $readings.data.Count-1; $f++)
{
If ($($readings.data[$f].id) -gt 0)
{
"INSERT INTO dbo.Table1 VALUES('$($readings.data[$f].id)'
,'$($dataGroup1.data[$i].id)'
,convert(date,dateadd(S,$($readings.data[$f].reading_time),'1970-01-01'))
,'$($readings.data[$f].Data1)'
,'$($readings.data[$f].Data2)'
,'$($readings.data[$f].Data3)'
,'$($readings.data[$f].Data4)'
,'$($readings.data[$f].Data5)'
,'$($readings.data[$f].Data6)'
,'$($readings.data[$f].Data7)'
,'$($readings.data[$f].Data8)'
,convert(date,dateadd(S,$($readings.data[$f].Data9), '1970-01-01'))
,'$($readings.data[$f].Data10)'
,GETDATE())"
} Start-Sleep -Seconds 3
}
}