Skip to main content

This isn't a worklet because if you are like us and are constantly battling disconnected agents or agents that never even made it to the portal you will have to resort to your MDM to resolve.  In our case, the agents are installed, service running, but not connected. We tried restarting the service but had no effect. 75% of the MDM installs of automox agent went fine, so it is not our install strategy.

What we had to do is run the readily available amox cleaner script and then re-install the app. But we needed something to trigger it off of and Automox has nothing to determine on the client side if the agent is either in the portal or connected.  We ended up creating a powershell with an API Call to check if the computer was A) in the portal and 😎 connected. Again, a quick search for something like Automox agent clean or something similar will yield you the removal script which properly removes the service.  Here you go…
 


function Check-Connection
{
# Define the API endpoint and token
$baseUrl = "https://console.automox.com/api"
$token = "PLACE TOKEN HERE" # Replace with your actual API token

# Get the computer name from the local environment variable
$computerName = $env:COMPUTERNAME
# Set up the headers for the API request
$headers = @{
"Authorization" = "Bearer $token"
}

# Initialize variables for pagination
$limit = 500
$page = 0
$foundComputer = $null

# Loop through pages until the computer is found or no more pages
do {
# Construct the full API URL with pagination parameters
$apiUrl = "$baseUrl/servers?display_name=$computerName&limit=$limit&page=$page"

# Make the API request
$response = Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Get

# Check if the response contains the computer
if ($response) {
$computer = $response | Where-Object { $_.display_name -eq $computerName }
if ($computer) {
$connectionStatus = $computer.connected
if ($connectionStatus) {
Write-Output "Connection status for ${computerName}: Connected"
exit
} else {
Write-Output "Connection status for ${computerName}: Not connected, continuing..."
$foundComputer = $computer

##place action here
}
} else {
Write-Output "No response from the API."
break
}

# Increment the page number for the next request
$page++
} while ($response.Count -eq $limit)

# Output the result if the computer was not found
if (-not $foundComputer) {
Write-Output "Computer ${computerName} not found in the API response."

##place action here
}
}





 

Be the first to reply!

Reply