Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepowershell
$headers = @{
    "x-api-key" = "{API KEY}"
    "Content-Type" = "application/json"
}
$body = "{}"
$outputData = @()

$response = Invoke-RestMethod -Uri 'https://{BASE URL}/gytpolapi/v2.0/get_misconfigurations_start' -Method 'POST' -Headers $headers -Body $body

do {
    # Convert response to JSON and output
    $response | ConvertTo-Json -Depth 3

    # Accumulate data for each iteration
    $outputData += $response

    # Prepare next request body
    $body = @{ token = $response.token } | ConvertTo-Json
    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    
    # Make next request
    $response = Invoke-RestMethod -Uri 'https://{BASE URL}/gytpolapi/v2.0/get_misconfigurations_next' -Method 'POST' -Headers $headers -Body $body
} until ($response.computers.Count -eq 0)

# Export all the data to a JSON file
$outputData | ConvertTo-Json | Set-Content -Path "C:\path\to\output_data.json"

...