Clean up Automox Licenses

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

	$apiUrl = "$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 = $
            $orgID = $server.organization_id

            Write-Host $server.display_name ": initiating delete."
            $delURI = "" + $serverID + "?o=$orgID"
            Write-Output $delURI
            Invoke-WebRequest -Method Delete -Uri $delURI -Headers $headers
} while ($maxItems -ne 0)

That’s an interesting one - thanks.

I had always thought that if a disconnected device with the endpoint installed is removed from the console, it will claim a license when the device reconnects. It was a long time ago when I went over our allocation, so I could be wrong.

From my conversations with support, removing a device from the console will cause the agent to uninstall itself.

I must try that out. I know from past experience that I have went over my license allocation by turning on an old laptop that still had a client on it. That was in 2017 though, so things might have changed.

That’s changed - if you uninstall in the console while the endpoint is off, then next time that endpoint checks in the uninstall command will be pushed down to the endpoint rather than it re-registering in the console. If you’re still seeing this behavior with any of your endpoints let me know so we can get support investigating.

That’s interesting to know. As I had been caught out in the past, I have always been concerned about using my full allocation of licenses. It has not happened for years now, so I am sure from what you say it can’t happen now.

1 Like