Skip to main content
Answer

API powershell loop to get VM details stops after around 90 calls

  • October 3, 2025
  • 2 replies
  • 38 views

Forum|alt.badge.img+6

Hello team,

I'm trying to write a script that executes a powershell script

 

1st API call works well and I can obtain a list of the VMs and associated GUID

$response = Invoke-RestMethod -Uri "$cvApiUrl/v4/virtualmachines" -Method Get -Headers $cvHeadersGet -UseBasicParsing

 

for the second step of the script I am getting details of the VMs and store them on a table.
 

foreach ($vm in $allVMs) {
    $uuid = $vm.UUID
    $vmName = $vm.name

    Write-Host "--- Processing VM : $vmName ---"
    Write-Host "URL : $cvApiUrl/VM?guid=$uuid"

    try {
        $vmDetail = Invoke-RestMethod -Uri "$cvApiUrl/VM?guid=$uuid" -Method Get -Headers $cvHeadersGet -UseBasicParsing

 

After 90 call I got this error

WARNING: Erreur récupération détail VM VM1 (attempt1) : The underlying connection was closed: An unexpected error occurred on a send.
WARNING: Erreur récupération détail VM VM2 (attempt2) : The underlying connection was closed: An unexpected error occurred on a send.
WARNING: Erreur récupération détail VM VM3  (attempt3) : The underlying connection was closed: An unexpected error occurred on a send.

 

Do you know if there is a limitation for API calls ?


I  have also tried to renew the token after 50 VM but same

I have tried to put a wait between each call 10s, same issue :(

 

Your help would be appreciated !

 

Thanks

 

 

Best answer by BloopaAgain

Hello,

 

it seems that the issue is related to how Powershell performs the API calls.
I have converted the same script to Python and now it works perfectly ! even with a pause of 0,1s between each call. after 700 calls, the script was able to retrieve the details of all VMs.
Thanks 

 

2 replies

Forum|alt.badge.img+12
  • Vaulter
  • October 6, 2025

Hi ​@BloopaAgain ,

Kindly gather the following details, along with the Commserv , webserver database and logs, and create a case with support team to review this further, as it appears to be related to a limitation or timeout issue:

The below information will help us review further and update next step.

  1. CS and Web Server version

  2. Whether a proxy is configured on any of these machines.


Forum|alt.badge.img+6
  • Author
  • Byte
  • Answer
  • October 6, 2025

Hello,

 

it seems that the issue is related to how Powershell performs the API calls.
I have converted the same script to Python and now it works perfectly ! even with a pause of 0,1s between each call. after 700 calls, the script was able to retrieve the details of all VMs.
Thanks