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.
$cve = 'DESIRED_CVE'
- Set the CVE
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'
$cve = 'CVE-2020-0689'
$filepath = 'C:\Temp\cve.csv'
# ---------------------------
$page = 0
$limit = 500
$servers = @()
$apiInstance = 'https://console.automox.com/api/'
$apiTable = 'servers'
Set-Content $filepath -Value "Computer,display_name,version,installed,$cve"
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
$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 {$_.cves -Contains $cve} | Select-Object @{label=”Computer”; Expression= {"$serverName"}},Display_Name,Version,Installed `
| Sort-Object Display_Name | Export-Csv -Path $filepath -NoTypeInformation -Append -Force
}