Greetings all,
I’m looking for a worklet that will allow me to enter in whatever number of days I’d like and to generate a list of systems that are at or above that number of days offline. There seems to be a few existing worklets that may be able to be modified to perform that function, but I’m not the best script editor out there.
I also found this, and it would also accomplish the same thing plus move them into their own group, but I can’t get it to do anything when I run it: Powershell script to move devices that have been disconnected longer than X days to a group | Community (automox.com)
Solved
Worklet to identify disconnected workstations over a specific age
Best answer by jack.smith
This script will use the Automox API and give you a column “Inactive Status” to state whether the agent has been disconnected in the range you stated or not. I’d also pay attention to the ‘last scan’ timestamp which may indicate another issue.
# Days Inactive
$DaysInactive = 14
$exportpath = 'C:\temp\automox-agents.csv'
# Get Your Org Info
$apiKey = Read-Host "api-key: "
$orgID = Read-Host "OrgID: "
$headers = @{ "Authorization" = "Bearer $apiKey" }
# Collect all devices from Automox
$i = 0
$agents = do{
$url = "https://console.automox.com/api/servers?o=$orgID&limit=100&page=$i"
$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json
$response
$i++
}
while ($response)
$inactive = (Get-Date).AddDays($DaysInactive)
$axout = $agents | ForEach-Object {
# Get just username without FQDN or UPN
$user = $_.last_logged_in_user
$username = switch -wildcard ($user)
{
"*\*" {$user -replace [regex]".*\\",""}
"*@*" {$user -replace [regex]"\@.*",""}
Default {$user}
}
# Determine last disconnected time and if the device is inactive
IF($_.last_disconnect_time)
{
$disconnect = [datetime]::parse($_.last_disconnect_time) -f 'g'
IF($disconnect -lt $Inactive)
{
$status = 'Inactive'
}
else
{
$status = 'Active'
}
}
else
{
$status = 'Active'
}
# Get last time device was scanned by Automox
IF($_.last_refresh_time)
{
$lastscan = [datetime]::parse($_.last_refresh_time) -f 'g'
}
# Build output object
[pscustomobject] @{
'hostname' = $_.name
'Inactive Status' = $status
'last scan' = $lastscan
'last disconnect' = $disconnect
'user' = $username
'OS' = $_.os_name
'OS_Ver' = $_.os_version
'last_logged_in_user' = $_.last_logged_in_user
'serial' = $_.serial_number
'memory' = $_.detail.ram / 1GB
'agent version' = $_.agent_version
'Missing # Patches' = $_.patches
'Reboot Required' = $_.needs_reboot
}
}
$axout | Export-Csv $exportpath -NoTypeInformation
Reply
Login to the community
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.