Skip to main content

I found this useful to create a csv file of pending patches. Remember to change the API key, the org ID and the group ID with yours. Also, the limit=500 can be adjusted to however many server names you want to return. This is run on a machine, not a worklet.

 

# Define your API Key
$apiKey = 'yourapikey'

# Define headers with your API Key
$headers = @{ "Authorization" = "Bearer $apiKey" }

# Define the URL for the pre-patch report API endpoint
$url = 'https://console.automox.com/api/reports/prepatch?o=yourshere&groupId=yourshere&limit=500&offset=0'

# Use Invoke-WebRequest to call the API
$response = Invoke-WebRequest -Method Get -Uri $url -Headers $headers

# Convert the response from JSON to a PowerShell object
$data = $response.Content | ConvertFrom-Json

# Initialize an empty array to store the results
$results = @()

# Loop through each device in the response
foreach ($device in $data.prepatch.devices) {
    # Loop through each patch for this device
    foreach ($patch in $device.patches) {
        # Create a new object with the device and patch information
        $result = New-Object PSObject -Property @{
            'ServerName' = $device.name
            'PatchName'  = $patch.name
            'Severity'   = $patch.severity
            'PatchTime'  = $patch.patchTime
        }

        # Add this object to the results array
        $results += $result
    }
}

# Export the results to a CSV file
$results | Export-Csv -Path 'C:\temp\file.csv' -NoTypeInformation
 

Be the first to reply!

Reply