I cobbled this together from several items in the Automox Labs and API documentation:
$orgID = "myorgid"
$apiKey = 'myapikeyhere'
$filepath = ‘.\ServerInventory.csv’
$page = 0
$limit = 500
$data = @()
Write-Output "Page"
while($true) {
$headers = @{"Authorization" = "Bearer $apiKey" }
$url = "https://console.automox.com/api/servers?$orgID?l=$limit&p=$page"
$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json
Write-Output $page
$data += $response
$page += 1
if($response.count -lt $limit) {
break
}
}
$data | Group-Object display_name | Sort-Object name | Select-Object Count,name `
| Export-Csv -Path $filepath -NoTypeInformation
The result is that it produces a csv of 500 server names as I’d expect. When I change “$page” to “1” in the script (and change the csv output file name) and run it again, it produces a new, blank csv.
I’ve read this: About Automox API
and feel like I’m doing it correctly, but it seems like I may be missing something - or am just doing something wrong.
Thoughts?