Server Detail Report - Example API PowerShell Script

Here is an API PowerShell script to export your Device Name, Model, Vendor, and Serial Number into a csv.

If you have tried this, you may have found it can be tricky, as the model, vendor, and serial number are stored in a nested field named detail. This script provides the expanded “detail” column data for each device by name.

Example Code:

#Update these variables with your API Key and orgID.  This script expects the $expDir path to already exist.#
$apiKey = 'YOUR_API_KEY'
$orgID = 'YOUR_ORG'
$expDir = 'C:\Temp' 
#############################################################################################################

#Pull server detail from API and export as csv to defined directory
$uri = "https://console.automox.com/api/servers?o=$orgID&api_key=$apiKey"
$responseJson = (Invoke-WebRequest -UseBasicParsing -Uri $uri).Content | ConvertFrom-Json 
$Output =  $responseJson | Select-Object NAME -ExpandProperty detail | Select-Object NAME, MODEL, VENDOR, SERIAL | Export-Csv -Path $expDir\detail.csv -NoTypeInformation -Force

If you would like to review all the information in the detail column along with the device name, you can change this section:

| Select-Object NAME, MODEL, VENDOR, SERIAL | Export-Csv -Path $expDir\detail.csv -NoTypeInformation -Force

to this:

| Select-Object * | Out-Gridview

This will output your information in an interactive PS table where you can filter and sort. I suggest using the Out-Grid view as some of the detail columns do export cleanly to a csv. From the PS table, you can sort and filter your data, then copy and paste into another file type of your choice.

Hope this helps!

2 Likes

This is great, super helpful. How about to pull this same list but for a specific group? (Assuming we know the group ID)

Hello @agranados,
I had a “verbose” version of the following script posted that would filter by group. After talking to one of our software engineers, I have a better solution to share. You can add the groupID as a filter in your API call directly. This is good for a few reasons. It simplifies the PS code, and it accounts for the the API returning a maximum of 500 items per call. This will let you get all members of a group with 500 or less devices without adding additional context for number of pages or length.

Example Code:

#Update these variables with your API Key and orgID.  This script expects the $expDir path to already exist.#
$apiKey = 'YOUR_API_KEY'
$orgID = 'YOUR_ORG'
$grpID = "Your_GROUP_ID"
$expDir = 'C:\Temp'
#############################################################################################################

#Pull server detail by group from API and export as csv to defined directory
$uri = "https://console.automox.com/api/servers?o=$orgID&groupId=$grpID&api_key=$apiKey"
$responseJson = (Invoke-WebRequest -UseBasicParsing -Uri $uri).Content | ConvertFrom-Json 
$Output =  $responseJson | Select-Object Name -ExpandProperty detail | Select-Object Name, MODEL, VENDOR, SERIAL | Export-Csv -Path $expDir\detail.csv -NoTypeInformation -Force 
3 Likes