Reached out to support and they said they didnt have a way to bulk remove duplicate devices .
They have this link but its a little lacking.
https://developer.automox.com/openapi/axconsole/operation/deleteDevice/
With Chat GPT and a little trouble shooting, i came up with this powershell script that worked for me.
you will need to do an export of all devices, find the duplicates and get a list of device id’s and put them in column A with deviceid as the header, save as *.csv.
Enjoy!
#Add api key and orgid!
$apiKey = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$orgId = xxxxxx
$headers = @{
"Authorization" = "Bearer $apiKey"
"Content-Type" = "application/json"
}
#Edit csv path and log path!
# Paths
$csvPath = "C:\Path\*.csv"
$logPath = "C:\Path\*.txt"
# Clear previous log
if (Test-Path $logPath) {
Remove-Item $logPath
}
New-Item -Path $logPath -ItemType File -Force | Out-Null
# Read device IDs
$deviceIds = Import-Csv -Path $csvPath
foreach ($row in $deviceIds) {
$deviceId = $row.DeviceId
if (-not vstring]::IsNullOrWhiteSpace($deviceId)) {
$url = "https://console.automox.com/api/servers/" + $deviceId + "?o=$orgId"
write-output $url
try {
$response = (Invoke-WebRequest -Method Delete -Uri $url -Headers $headers).Content
$successMsg = "$(Get-Date -Format 'yyyy-MM-dd HHss') -
Deleted device ID ${deviceId}: $($response.StatusCode) $($response.StatusDescription)"
Write-Host $successMsg
Add-Content -Path $logPath -Value $successMsg
}
catch {
$errorMsg = "$(Get-Date -Format 'yyyy-MM-dd HHss') -
Failed to delete device ID ${deviceId}: $($_.Exception.Message)"
Write-Host $errorMsg
Add-Content -Path $logPath -Value $errorMsg
}
}
else {
$skipMsg = "$(Get-Date -Format 'yyyy-MM-dd HHss') -
Skipped empty or invalid DeviceId row."
Write-Host $skipMsg
Add-Content -Path $logPath -Value $skipMsg
}
}