I am not sure if anyone has this need (or if this has been posted before), but here’s a little Powershell script you can run with a scheduled task to delete hosts that have not reported back to Automox after xxx days. I have this configured on a server and it helps me manage the Automox licenses automatically.
#Define API Key and URL to get initial Machine list
$apiKey = "<insert your API key here>"
$headers = @{"Authorization" = "Bearer $apiKey"}
$lengthPerPage = 100
$pageCounter = 0
$maxItems = 0
$maxDays = 30
do
{
$apiUrl = "https://console.automox.com/api/servers?l=$lengthPerPage&p=$pageCounter"
$response = Invoke-RestMethod $apiUrl -Method 'GET' -Headers $headers -Body $body
$a = $response | ConvertTo-Json
$maxItems = $response.results.count
$currentItem = 0
foreach($server in $response.results)
{
$lastCheckin = Get-Date
if ($server.last_disconnect_time)
{
$lastCheckin = =datetime]$server.last_disconnect_time
}
$span = New-TimeSpan -Start $lastCheckin
Write-Host $server.display_name $span.days "days last seen"
if ($span.Days -ge $maxDays)
{
$serverID = $server.id
$orgID = $server.organization_id
Write-Host $server.display_name ": initiating delete."
$delURI = "https://console.automox.com/api/servers/" + $serverID + "?o=$orgID"
Write-Output $delURI
Invoke-WebRequest -Method Delete -Uri $delURI -Headers $headers
}
}
$pageCounter++
} while ($maxItems -ne 0)