# 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