Use API to Get a Hardware Inventory of Your Organization

This API script will give you a hardware inventory in addition to some basic OS info and agent version.

You’ll need to set the following before running the script:

$apiKey = 'YOUR_API_KEY' - in your console, go to Settings->API and select the API key. Note that the API key is per admin user, so you and another admin in your console will have different API keys.

$orgID = 'YOUR_ORG_ID' - put in your Org ID which can be found by looking at the URL on the dashboard and selecting the value after the “?o=”: [https://console.automox.com/dashboard?o=1234]. In this example, the Org ID is 1234.

You can also modify $filepath if you want to change the file name or save it in a different location. Keep in mind the script will overwrite a previously generated file if it exists.

# Update these variables with your API Key, orgID & save directory/filename 
# This script expects the $expDir path to already exist and will overwrite an existing file

$apiKey = 'YOUR_API_KEY'
$orgID = 'YOUR_ORG_ID'
$expDir = 'C:\Temp\hardware.csv'

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

#############################################################################################################

while($true) {

    $uri = "https://console.automox.com/api/servers?o=$orgID&api_key=$apiKey&l=$limit&p=$page"
    $resp = (Invoke-WebRequest -Method GET -Uri $uri -UseBasicParsing).Content | ConvertFrom-Json | Select-Object results 

    $Output =  $resp.results | Select-Object Name, serial_number, last_logged_in_user, needs_reboot, os_name, os_version, agent_version, last_disconnect_time -ExpandProperty detail `
        | Select-Object Name, MODEL, VENDOR, CPU, @{ Name = 'RAM (GB)'; Expression = { [math]::Round(($_.RAM/1073741824)) }}, SERVICETAG, VERSION, `
            serial_number, last_logged_in_user, needs_reboot, os_name, os_version, agent_version, last_disconnect_time

    $servers += $Output
    $page += 1

    if($resp.results.Count -lt $limit) {
        break
    }
}        

$servers | Export-Csv -Path $expDir -NoTypeInformation -Force
1 Like