Autofix - CWC RMM+ - Offline Agent Remediation
Summary
This script will restart agent services or attempt to reinstall the agent if restarting the services fails.
Replaces:
- CW Control RMM+ API - Offline Agent Remediation (Agent Reinstall) [Autofix, Globals, Ticket]*
- CW Control RMM+ API - Offline Agent Remediation (Agent Restart) [Autofix, Globals, Ticket] - V2
Sample Run
This script is an autofix to a monitor and should not be manually run.
Dependencies
- Agent Install - Generate Location URL
- CWM - Control - Script - CW Control RMM+ API - Is Online [Properties]*
- CWM - Control - Script - CW Control RMM+ API - Execute Command*
- SWM - Software Install - Script - CW Control RMM+ API - LTPosh Redo-LTService*
- CWM - Automate - Monitor - No Checkin for More Than 30 Days*
- LTPoSH Community Module (https://bit.ly/LTPoSH)
- RMM+ Plugin Configured in CW Control portal
- System Properties (See below)
Global Parameters
| Name | Example | Required | Description | 
|---|---|---|---|
| Re-Install | 1 or anything else | Defaulted to 1 | 1 enables the reinstallation of the agent if restarting the services fails; 0 will not attempt a reinstall if restarting services fail. | 
| TicketingEnabled | 1 or anything else | Defaults to 1 | 1 enables the creation of tickets; anything else disables it. | 
| TicketCreationCategory | 0 or anything else | Defaults to 164 | This is used in the event of a success status to determine if a finish ticket is appropriate; 0 indicates no ticket finishing is required. | 
| DuplicateCheck | 0 or anything else | Defaults to 0 | Anything but 0 enables a duplicate check; 0 will not check for duplicates. | 
Script States
| Name | Example | Description | 
|---|---|---|
| AgentStatus | Broken for computer 1234 | Reflects an agent status (online, offline, broken). | 
Process
- If Status is False
- If DuplicateCheck is anything but 0
- Get SerialNumber
- Count the number of identical serial numbers in the database
- If Count does not equal 0
- Log message
- Select the most recent Computer ID for this computer
- Delete WHERE ComputerId is anything except the most recent Computer ID and BIOS version is the Serial Number and ClientId is the Client ID.
- If the last contact of this machine is within the last 15 minutes
- Log that the computer is online
- Exit the script
 
- Start initial check
 
 
- Start initial check
 
- If DuplicateCheck is anything but 0
- Initial check
- Run the API - is online script
- If the computer is not online
- Log agent offline
- Set the script state to Offline for computer ###
- Exit script
 
- Log agent is online
- Set the registry key DisableRootAutoUpdate= 0 at the pathHKLM://SOFTWARE//Policies//Microsoft//SystemCertificates//AuthRoot.
- Push agent service restart command to ConnectWise control via RMM+
- While contact attempt is less than three
- Sleep 5 minutes
- Add 1 to attempt
- Check the connection state
- If the state of the agent is not online
- If it's not the 3rd attempt
- Return to 5.1
 
- If Re-Install agent is on
- Log state
- Run LTPoSH redo LTService script
- While contact attempt is less than 3
- Sleep 5 minutes
- Add 1 to attempt
- Check the connection state
- If the agent is still offline
- If it's not the 3rd attempt
- Return to 5.4.2.3
 
 
- If it's not the 3rd attempt
- Log that the agent is online
- Clear the script state
- Exit script
 
 
- Log broken agent
- Set state to broken for Computer ###
- If ticketing is not enabled
- Exit with error
 
- Create ticket
 
- If it's not the 3rd attempt
 
- Log the situation
- Set the state to Broken for Computer ###
- Reset the value of the registry key DisableRootAutoUpdate, if it was 1 before restarting the agent.
- If ticketing is not enabled
- Exit with error
 
- Set the ticket subject, body, and ID
- If the ticket ID is anything but 0
- Comment ticket to admin
- Exit script
 
- Create ticket
- Exit
 
- Reset the value of the registry key DisableRootAutoUpdate, if it was 1 before restarting the agent.
- Log that the Automate Agent is online
- Clear the script state
- Exit script
Output
- Script log
- Script state
Change Log
01-2023: Added functionality to handle registry key entry preventing repair.