Versions Compared

Key

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

...

Example script to extract a list of all reporting devices and their misconfigurations

Code Block
languagepowershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add( @{
    "x-api-key", = "{API KEY}")
$headers.Add(
    "Content-Type", = "application/json")
}
$body = "{}"
$outputData = @()

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

do {
	$response | ConvertTo-Json -Depth 3
	  # 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
	 | ConvertTo-Json

    # Make next request
    $response = Invoke-RestMethod -Uri 'https://{BASEURLBASE URL}/gytpolapi/v2.0/get_misconfigurations_next ' -Method 'POST' -Headers $headers -Body $body	
} until ($response.computers.Count -eq 0 -or $iteration -eq 5)

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

get_miscon_computers_start

...