Skip to main content

Use API to Pull a List of All Outstanding Critical Updates and the Age of the Update

  • December 22, 2020
  • 4 replies
  • 218 views

Tony-Automox

This script will dump all available critical updates for all of the endpoints in an organization into a .csv file along with the number of days the update has been available and if the update requires a reboot.

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.

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

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

Set-Content $filepath -Value "Computer,display_name,Age(Days),requires_reboot"

$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
    
    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 $false -and $_.severity -EQ 'critical'} `
              | Select-Object @{label=”Computer”; Expression= {"$serverName"}},Display_Name,`
                @{label=”Age(Days)”; Expression= {(New-TimeSpan -Start ([System.DateTime]::ParseExact($_.create_time,'yyyy-MM-ddTHH:mm:ss+0000',$null))).Days}},requires_reboot `
              | Sort-Object $_.Display_Name | Export-Csv -Path $filepath -NoTypeInformation -Append -Force

}

4 replies

Forum|alt.badge.img
  • Novice
  • 6 replies
  • August 11, 2023

I know this is pretty old, but the script does not write anything to the csv?


Forum|alt.badge.img
  • Novice
  • 6 replies
  • August 31, 2023

Disregard,


  • Rookie
  • 2 replies
  • February 5, 2025

Hi, are there any updates to this?  It looks like it would be useful but it does not work anymore.  I have verified with other scripts that API and ORG key are working.  thanks in advance!

 

At line:77 char:15
+               | Select-Object @{label=”Computer”; Expression= {"$serv ...
+               ~
An empty pipe element is not allowed.
At line:81 char:15
+               | Sort-Object $_.Display_Name | Export-Csv -Path $filep ...
+               ~
An empty pipe element is not allowed.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : EmptyPipeElement


  • Rookie
  • 2 replies
  • February 5, 2025

I see the issue, AutoMox doesn’t support “Critical” on the particular LinuxOS I am using.


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