Use API to Pull Software Inventory for Every Computer in an Organization

  • 25 November 2020
  • 10 replies
  • 935 views

Userlevel 5
  • Automox Employee
  • 36 replies

Using the standard API call for software packages installed will just give you software installed on a single device referenced by the server ID#. This script will give you software packages installed on every device in an organization referenced by the computer names. By altering the script you can add additional fields - but make sure the Set-Content line reflects all of the fields you add to the Select-Object part of the last line of the script. You’ll also want the Set-Content line to have the fields in the same order as the Select-Object.

 

Available fields can be found here from the Response tab:

https://developer.automox.com/openapi/axconsole/operation/getDevicePackages/

 

 

You can also modify it to do things like not show Windows updates & hotfixes by altering the Where-Object part of the last line of the script. For example:

Where-Object {$.installed -EQ $true -and $.repo -notlike “Windows*”}

 

 

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.

 

 

# Set these -----------------



$apiKey = 'YOUR_API_KEY'

$orgID = 'YOUR_ORG_ID'

$filepath = 'C:\Temp\SoftwareInventory.csv'



# ---------------------------



$page = 0

$limit = 500

$servers = @()



Set-Content $filepath -Value "Computer,display_name,version"



$apiInstance = 'https://console.automox.com/api/'

$apiTable = 'servers'



while($true) {



$orgAndKey = "?o=$orgID&api_key=$apiKey&l=$limit&p=$page"



# Put components together

$uri = $apiInstance + $apiTable + $orgAndKey



$resp = (Invoke-WebRequest -Method GET -Uri $uri -UseBasicParsing).Content | ConvertFrom-Json | Select-Object results



$servers += $resp.results

$page += 1



if($resp.results.count -lt $limit) {

break

}

}



$servers = $servers | Sort-Object name



# Check each server for software

foreach ($server in $servers) {



$serverID = $server.id

$serverName = $server.name



Write-Output $serverName



$orgAndKey = "/$serverID/packages?o=$orgID"



# Put components together

$getURI = $apiInstance + $apiTable + $orgAndKey



$headers = @{ "Authorization" = "Bearer $apiKey" }

$response = (Invoke-WebRequest -Method Get -Uri $getURI -Headers $headers).Content | ConvertFrom-Json



$response | Where-Object {$_.installed -EQ $true} `

| Select-Object @{label=”Computer”; Expression= {"$serverName"}},Display_Name,Version `

| Sort-Object Display_Name | Export-Csv -Path $filepath -NoTypeInformation -Append -Force



}


10 replies

@Tony - do you have a script that will pull for a specific software that contains a specific name?

Userlevel 5

Like this? Use API to Determine if a Certain Software is Installed on All Devices

Badge

Hi Tony @Tony , i´m trying to modify the script to not include info about any Intel*, Security update*, Update*, in the report, to try to be more accurate with the software that appear in the installed programs in the control Panel, but for now i can´t figure out a way to exclude that in the Script. For us that would be a good report to present to our clients.


Any help would be appreciated to remove that particular info, and any other from the script.


Regards

HI Everyone,


Is there a way to incorporate a group ID as well?


We have the requirement to create a software list / audit for certain groups?


Thank you.


Dan

Badge

This is not working.

Badge

I’m getting an error on this software inventory.

 

At C:\Program Files (x86)\Automox\execDir043744995\execcmd071137510.ps1:107 char:15
+               | Select-Object @{label=�??Computer�??; Expression= {"$ ...
+               ~
An empty pipe element is not allowed.
At C:\Program Files (x86)\Automox\execDir043744995\execcmd071137510.ps1:109 char:15
+               | Sort-Object Display_Name | Export-Csv -Path $filepath ...
+               ~
An empty pipe element is not allowed.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : EmptyPipeElement
 

COMMAND TIMED OUT.

same error for me any one fixed it?

@rasejo @Shasan This powershell script is meant to run from your workstation not as a worklet. You need to plug in your api and org key explained by Tony. 

@rasejo @Shasan This powershell script is meant to run from your workstation not as a worklet. You need to plug in your api and org key explained by Tony. 

Just ran this from my workstation using an admin powershell window. Same error. Opening it in the Powershell ISE, I see it reports the same error at both pipe symbols on lines 107 and 109. Not really sure what to do about it, though.

@rasejo @Shasan This powershell script is meant to run from your workstation not as a worklet. You need to plug in your api and org key explained by Tony. 

yes i know, and i am running it from powershell not worklet. im getting error

Reply