Skip to main content

Use API to Get a Hardware Inventory of Your Organization


Tony-Automox

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

4 replies

Forum|alt.badge.img
  • Novice
  • 5 replies
  • September 15, 2022

I tried this and implemented it as a worklet but it doesn’t work.


Forum|alt.badge.img
  • Novice
  • 5 replies
  • September 15, 2022

Nevermind, I got it to work! 


Forum|alt.badge.img
  • Rookie
  • 2 replies
  • January 9, 2023

Hello, I’m getting the following error:

 

At C:\Program Files (x86)\Automox\execDir449380431\execcmd435511650.ps1:58 char:9
+         | Select-Object Name, MODEL, VENDOR, CPU, @{ Name = 'RAM (GB) ...
+         ~
An empty pipe element is not allowed.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : EmptyPipeElement
 

COMMAND TIMED OUT.


I know this is kind of a long shot and necro of this thread, but I just found this script yesterday and it’s amazing!

My only question is could it be tweaked to pull the system volume/HDD/SSD as well? I don’t need to see the free space or anything just the total volume size of any HDD/SSD on the device. I see it’s one of the items you can query via the API, but it’s a bit Greek to me on how to add it to the script itself to extract the data.

I use Snipe-IT and custom hardware fields for our inventory (CPU, HDD, RAM,ETC), so with the extra info pulled from the Automox devices I can do a straight import of pretty much the entire hardware spec straight from this script to the Snipe-It asset system.

Thanks for any assistance anyone with knowledge on this can provide!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings