Use API for a Count of All Software Installed in an Organization (with Pagination)

  • 5 February 2021
  • 0 replies
  • 1 view

Userlevel 5
  • Automox Employee
  • 37 replies

This API call will generate a list of all software in your organization and a count of how many are installed of each. Just update your API key, org ID, and where you want the file saved. It will overwrite an existing file if it exists.


It also shows how you can use pagination to account for more than 500 results.


$apiKey = 'YOUR_API_KEY'
$orgID = 'YOUR_ORG_ID'
$filepath = "C:\Temp\packages.csv"

$page = 0
$limit = 500
$data = @()

Write-Output "Page"

while($true) {
$headers = @{"Authorization" = "Bearer $apiKey" }
$url = "https://console.automox.com/api/orgs/$orgID/packages?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

0 replies

Be the first to reply!

Reply