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

  • 7 December 2020
  • 4 replies
  • 93 views

Userlevel 5
  • Automox Employee
  • 37 replies

This was originally written for a customer that wanted to see if every system in their environment had Sophos Antivirus installed or not - and what version if they did.


$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.


$appInstalled = 'APPLICATION' - put the name of the application as it is listed in the software section of a device’s page that has it installed.


$filepath - The save location and file name for the .csv file generated.


Here’s a sample output checking for Microsoft Edge Chromium:

2020-12-07 14_12_24-AppInstalled - Google Sheets


$apiKey = 'YOUR_API_KEY'
$orgID = 'YOUR_ORG_ID'

$appInstalled = 'Microsoft Edge'
$filepath = 'C:\Temp\AppInstalled.csv'

Set-Content $filepath -Value "Computer,Name,Version"

$apiInstance = 'https://console.automox.com/api/'
$apiTable = 'servers'
$orgAndKey = "?o=$orgID&api_key=$apiKey"

# Put components together
$getURI = $apiInstance + $apiTable + $orgAndKey

# Get the json body of the Web Request
$jsonReturn = (Invoke-WebRequest -UseBasicParsing -Method Get -Uri $getURI).Content

# Convert to object with manipulatable properties/values
$servers = $jsonReturn | ConvertFrom-Json
$servers = $servers | Sort-Object name

# Check each server for software
foreach ($server in $servers) {

$serverID = $server.id
$serverName = $server.name

$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

$installed = $response | Where-Object {$_.installed -EQ $true -and $_.display_name -EQ $appInstalled}

$output = $serverName + "," + $installed.display_name + "," + $installed.version
$output | Add-Content -Path $filepath

}

4 replies

Hello there,


I’m following all the steps exactly and I’m getting the report generated to the desirable path but there is no info for the application and its version in it for all 500 devices. I got only the names of the devices. I have tried with several application names taken from the software section of the device page.

Any ideas what I’m doing wrong?

Thank you in advance

Userlevel 2

How do I remove the limit of returning 500 systems. I have closer to 1200 that I need to query…

There’s not a way to remove the limit, but you can work with it by including some pagination handling in the code. See Use API to Pull Software Inventory for Every Computer in an Organization for an example of a script where that is being used.

Userlevel 3

I tweaked the code above to deal with pagination and pull all the devices. This should make it easier for folks. 

 

$apiKey = 'Your API Key'
$orgID = 'Your ORG ID'
$appInstalled = 'Adobe Acrobat*'
$filepath = 'C:\Temp\AppInstalled.csv'

Set-Content $filepath -Value "Computer,Name,Version"
$apiInstance = 'https://console.automox.com/api/'
$apiTable = 'servers'

####
#This will pull all devices and not just the first 500

$pageindex = 0
$Items = New-Object -TypeName "System.Collections.ArrayList"
$headers = @{ "Authorization" = "Bearer $apiKey" }

Do {
$url = "https://console.automox.com/api/servers?o=$orgID&page=$pageindex"
$Devices =(Invoke-restmethod -Method Get -Uri $url -Headers $headers)
foreach ($Item in $Devices) {$Items += $Item}
$pageindex++
}
Until ($Devices.count -lt 500)

####
# Check each server for software
foreach ($server in $Items) {
$serverID = $server.id
$serverName = $server.name
$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
$installed = $response | Where-Object {$_.installed -EQ $true -and $_.display_name -Like $appInstalled}
$output = $serverName + "," + $installed.display_name + "," + $installed.version
$output | Add-Content -Path $filepath
}

 

Reply