Skip to main content

Use API to Run a Needs Attention Report

  • January 14, 2025
  • 1 reply
  • 38 views

Forum|alt.badge.img
# Set mandatory variables
$apiKey = 'Your_API_Key'
$orgID = 'Your_OrgID'

# Set optional
$groupID = ''

# Where to save the file
$currentDate = (Get-Date).ToString("yyyyMMdd")
$output = "C:\Temp\NeedsAttention$currentDate.txt"

################################################## 

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

If ($groupID)
{
    $url = "https://console.automox.com/api/reports/needs-attention?o=$orgID&groupId=$groupID"
}
else
{
    $url = "https://console.automox.com/api/reports/needs-attention?o=$orgID"
}

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

# Extract the devices information
$devices = $data.nonCompliant.devices

# Create a table and format the output
$table = @()
foreach ($device in $devices) {
    $table += [PSCustomObject]@{
        ID                       = $device.id
        Name                     = $device.name
        CustomName               = $device.customName
        Created                  = (Get-Date $device.serverCreateTime).ToString("yyyy-MM-dd")
        LastScanned              = (Get-Date $device.lastRefreshTime).ToString("yyyy-MM-dd")
        Connect                  = $device.connected
        NeedReboot               = $device.needsReboot
        GroupID                  = $device.groupId
        OS_family                = $device.os_family
        Policies                 = $device.policies
        Compatible               = $device.isCompatible
        Disc30Days               = $device.disconnectedThirtyDays
        Compliant                = $device.compliant
    }
}

# Output the table to file
$table | Format-Table -Property ID, Name, CustomName, Created, LastScanned, Connect, NeedReboot, GroupID, OS_family, Policies, Compatible, Disc30Days, Compliant | Out-String | Out-File -FilePath $output

 

1 reply

Forum|alt.badge.img
  • Novice
  • 6 replies
  • March 4, 2025

Can you update to create a csv instead of a txt?

 

Thanks


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