Solved

Worklet to identify disconnected workstations over a specific age

  • 26 February 2024
  • 5 replies
  • 88 views

Badge

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)

icon

Best answer by jack.smith 4 March 2024, 16:39

View original

5 replies

Userlevel 3

Hi @ECHazlett !

The Windows - Maintenance Tasks - Cleanup Disconnected Automox Devices worklet in our Catalog should give you what you need!

It utilizes the Automox API to find devices that are in a disconnected state for longer than X days.

As this is an API script, you’ll want to target the worklet to a single device. This device will act as the host that runs the API script.  By using flexible device targeting within the worklet, you ensure that you are just scoping one host name.

I recommend taking a look at our Automox University course that demonstrates how to set up the worklet: https://university.automox.com/disconnected-device-cleanups

Let me know if you have any questions.

Have a great day!

Badge

Hi @ECHazlett !

The Windows - Maintenance Tasks - Cleanup Disconnected Automox Devices worklet in our Catalog should give you what you need!


I’ve looked at this script, the only issue I have with it is that it removes systems from Automox. I don’t want them removed, just listed, or better yet, moved. I’ll look at the other links and see if that aids in altering it to our needs.

Userlevel 3

Understood!


That worklet is defaulted to run in dry run mode. Meaning, devices that are in a disconnected state based on your X days threshold will be displayed to the Activity Log, but will not be deleted. This setting is controlled by the parameter $dryRun = $true

Devices would only be deleted from your console if you set $dryRun = $false

 

That said, you can run the worklet in dry run mode to create a list of devices that have been disconnected. You could then use a bulk action to move these devices to a desired group.

Badge

I’ve been able to get a report of systems, but I cannot get it to list systems between 1-29 days disconnected. It only shows me systems that are 30+ days offline even if I set the threshold lower. I can’t seem to find the code in the script that might be limiting that.

Userlevel 5
Badge +1

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