I am invoking an REST API to assemble a .csv with users of software products, but sometimes it got stuck on page 0 and providing the same information again and again until the taskscheduler stops the script. Running on PS version 5.1 and below is the do / while I am using. Is there any way to check if the loop is already stuck at page 0 or to avoid this?
$i = 0
do {
#invoke software products
$response = Invoke-RestMethod -Method GET -Uri "$aAppBaseUrl/software-products?size=2000&page=$i" -Headers $headers
#function execution block
myFunction
$i = $i + 1
$last = $response.last
} While ($last -eq $False)