Curley brasis is missing in output json file using PowerShell Script

Trying to fetch the response from the API. Sometimes output json file get generated with proper json with start and end brasis but sometimes end curley brasis “}” is missing in output file.
Expected :


Current Result:

Script :

$QueryResults = @()

Invoke REST method and fetch data until there are no pages left.

do {
$Results = Invoke-RestMethod -Headers $Headers -Uri $uri -UseBasicParsing -Method “GET” -ContentType “application/json”

        if ($Results.value) {
            $QueryResults += $Results.value
        } else {
            $QueryResults += $Results

        $uri = $Results.'@odata.nextLink'
} until (!($uri))

# Return the result.
$QueryResults | ConvertTo-Json -depth 100 | Out-File "C:\AzureAD.json"
Set-AzureStorageBlobContent -File "C:\AzureAD.json" -Container $ContainerName -Blob "SecurityGroups/AzureAD.json" -Context $Ctx -Force

Can someone help me out on this.

Welcome to the forum. :wave:t4:

Could you please go back, edit your question and fix the formatting of your code?

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink: