Jump to content
LLCoolWas

Uninstall and Reinstall Automate Agents through Control

Recommended Posts

Here is an easy way to silently uninstall and reinstall the ConnectWise Automate Agent through a Control Command.
All you need to do is replace the server FQDN inside the quotes on line 6, and the server password on line 8.
You can push it to many devices at once if you need to, but keep in mind your server's bandwith.
The script takes about 3 minutes to run on a single agent and ends with an output of the LTSVC Folder Contents and LTErrors.txt file in the Command History pane.
I suggest storing this in the "Command Toolbox" Extension for quick access.

AS ALWAYS: USE AT YOUR OWN RISK. I AM NOT RESPONSIBLE FOR ANYTHING.

Code:
#----Downloads Automate Uninstaller From your FQDN, Install or Download then Install Agent----
#!ps
#timeout=9000000
#maxlength=9000000
#ENTER YOUR FQDN INSIDE THE QUOTES ON THE LINE BELOW i.e.: 'http://automate.myfqdn.com'
$FQDN='http://automate.myfqdn.com'
#ENTER YOUR SERVER PASSWORD INSIDE THE QUOTES ON THE LINE BELOW (Located in the CONFIG table in the Automate database)
$SERVERPASS='syspass'
#--------------------------------------------------------
#--------------------------------------------------------
#--------------------------------------------------------
#--------------------------------------------------------
Write-Output "Your FQDN is set to: $($FQDN)"
Write-Output "Your System Password is set to: $($SERVERPASS)"
if (Test-Path c:\windows\ltsvc){
sc.exe config "LTService" start= disabled
sc.exe config "LTSvcMon" start= disabled
taskkill /im ltsvcmon.exe /f
taskkill /im lttray.exe /f
taskkill /im ltsvc.exe /f
$source = "$($FQDN)/labtech/service/LabUninstall.exe"
$Filename = [System.IO.Path]::GetFileName($source)
$dest = "C:\$Filename"
$wc = New-Object System.Net.WebClient
if (!(test-path $dest))
{if ((Test-Path $dest -OlderThan (Get-Date).AddHours(-24))){
Write-Output '-----------------------------------------'
Write-Output '------File is older than 24 hours old----'
Write-Output '------Deleting Old Uninstaller-----------'
Write-Output '-----------------------------------------'
remove-item C:\LabUninstall.exe}
Write-Output '-----------------------------------------'
write-Output '------Downloading Uninstaller Now--------'
Write-Output '-----------------------------------------'
Write-Output '-----------------------------------------'
$wc.DownloadFile($source, $dest)}
Else
{Write-Output '-----------------------------------------'
Write-Output '----Uninstaller Already Resides on C:\----'
Write-Output '---Using c:\Labuninstall.exe-------------'
Write-Output '---If you have issues with the uninstall-'
Write-Output '---Delete the uninstaller and run again--'}
Write-Output '-----------------------------------------'
Write-Output '---------------Uninstalling--------------'
C:\LabUninstall.exe /quiet /norestart
Write-Output '-----------------------------------------'
Write-Output '----Uninstall Started Waiting 90 Secs----'
Write-Output '-----------------------------------------'
Start-Sleep 90}
Else
{Write-Output '-----------------------------------------'
Write-Output '------LTSVC FOLDER DOES NOT EXIST--------'
Write-Output '-------SKIPPING UNINSTALL PROCESS---------'}
Write-Output '-----------------------------------------'
Write-Output '----------Download Agent Sequence---------'
Write-Output '-----------------------------------------'
$source2 = "$($FQDN)/labtech/service/LabTechRemoteAgent.msi"
$Filename = [System.IO.Path]::GetFileName($source2)
$dest2 = "C:\$Filename"
$wc = New-Object System.Net.WebClient
$file2 = 'C:\LabTechRemoteAgent.msi'
if (!(test-path $file2))
{if ((Test-Path $file2 -OlderThan (Get-Date).AddHours(-24))){
Write-Output '-----------------------------------------'
Write-Output '------File is older than 24 hours old----'
Write-Output '------Deleting Old Installer-----------'
Write-Output '-----------------------------------------'
remove-item C:\LabTechRemoteAgent.msi}
Write-Output '-----------------------------------------'
write-Output '--------Downloading Installer Now--------'
Write-Output '-----------------------------------------'
$wc.DownloadFile($source2, $dest2)}
Else
{Write-Output '----Installer Already Resides on C:\-----'
Write-Output '---Using c:\LabtechRemoteAgent.msi-------'
Write-Output '---If you have issues with the install---'
Write-Output '---Delete the installer and run again----'}
Write-Output '-----------------------------------------'
Write-Output '----------------Installing---------------'
Write-Output '-----------------------------------------'
msiexec.exe /i C:\LabTechRemoteAgent.msi /quiet /norestart SERVERADDRESS=$($FQDN) SERVERPASS=$($SERVERPASS)
Start-Sleep -s 60
Write-Output '-----------------------------------------'
Write-Output '------Verifying Services are Started-----'
Write-Output '-----------------------------------------'
sc.exe start ltsvcmon
sc.exe start ltservice
Write-Output '-----------------------------------------'
Write-Output '-------Contents of LTSVC Folder:---------'
Write-Output '-----------------------------------------'
ls c:\Windows\LTSVC
Write-Output '-----------------------------------------'
Write-Output '------Contents of LTErrors.txt File:-----'
Write-Output '-----------------------------------------'
type c:\windows\ltsvc\lterrors.txt

Share this post


Link to post
Share on other sites

This is interesting, thanks for sharing.

Do you have to have a control session open, or can this be run remotely/silently from Labtech/Automate?

Share this post


Link to post
Share on other sites
20 hours ago, illusionz said:

This is interesting, thanks for sharing.

Do you have to have a control session open, or can this be run remotely/silently from Labtech/Automate?

You do not have to have a control session open, and it can be run silently from your Control server's Access page. Make sure your server and client versions are up to date and match (I tested this with Control 6.4, but I think it should work on the last couple versions).

Share this post


Link to post
Share on other sites
2 hours ago, LLCoolWas said:

You do not have to have a control session open, and it can be run silently from your Control server's Access page. Make sure your server and client versions are up to date and match (I tested this with Control 6.4, but I think it should work on the last couple versions).

Awesome, thanks!

I wonder if there is a way to just simply restart a failed/stopped service without having to reinstall.

 

But this definitely will come in handy, Labtech service likes to stop or fail to install correctly all the time.

Share this post


Link to post
Share on other sites
11 hours ago, illusionz said:

Awesome, thanks!

I wonder if there is a way to just simply restart a failed/stopped service without having to reinstall.

 

But this definitely will come in handy, Labtech service likes to stop or fail to install correctly all the time.

Sure. I prefer to kill all 3 tasks then start the services. Just send this command:

taskkill /im ltservice.exe /f & taskkill /im ltsvcmon.exe /f & taskkill /im lttray.exe /f & sc start ltsvcmon & sc start ltservice

Share this post


Link to post
Share on other sites

In the CW Control Forums specifically, I posted how you can use Chris Taylors LTPOSH module with Control.

#maxlength=5000
#timeout=600000
"%windir%\system32\WindowsPowerShell\v1.0\powershell.exe" "(new-object Net.WebClient).DownloadString('http://bit.ly/LTPoSh') | iex; <MODULE COMMANDS>"

At the end of the command, just replace "<MODULE COMMANDS>" with the actual module function you want to use. Such as:

Restart Automate Sevices:          Restart-LTService
Reinstall Automate using the current Server and Location:          Reinstall-LTService
Make the agent register with a new AgentID:          Reset-LTService -ID -MAC

See: 

 

Share this post


Link to post
Share on other sites
13 hours ago, LLCoolWas said:

Sure. I prefer to kill all 3 tasks then start the services. Just send this command:

taskkill /im ltservice.exe /f & taskkill /im ltsvcmon.exe /f & taskkill /im lttray.exe /f & sc start ltsvcmon & sc start ltservice

Sweet Idea,

Do you throw that in a script itself?

Share this post


Link to post
Share on other sites
11 hours ago, DarrenWhite99 said:

In the CW Control Forums specifically, I posted how you can use Chris Taylors LTPOSH module with Control.


#maxlength=5000
#timeout=600000
"%windir%\system32\WindowsPowerShell\v1.0\powershell.exe" "(new-object Net.WebClient).DownloadString('http://bit.ly/LTPoSh') | iex; <MODULE COMMANDS>"

At the end of the command, just replace "<MODULE COMMANDS>" with the actual module function you want to use. Such as:

Restart Automate Sevices:          Restart-LTService
Reinstall Automate using the current Server and Location:          Reinstall-LTService
Make the agent register with a new AgentID:          Reset-LTService -ID -MAC

See: 

 

 

Not to sound like a total noob, and I'm grateful for everyone's help with this!

 

How would you run your top command?

Share this post


Link to post
Share on other sites
On ‎12‎/‎7‎/‎2017 at 12:46 PM, illusionz said:

How would you run your top command?

Exactly as shown. The command input window in Control supports multiple lines. You can't hit "Enter" or it will start executing, but you can paste multiple lines, I believe Shift-Enter will allow you to add the newlines in as needed. But honestly the simplest is copy/paste. 

Share this post


Link to post
Share on other sites

This is what I've created and been using for over a year. 

#!ps
#timeout=900000
#maxlength=9000000
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.psm1')
Install-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2

You can also use the other Functions too:

Confirm-Automate
Uninstall-Automate
Install-Automate
Push-Automate

GitHub (Download and publically hosted from)
https://github.com/Braingears/PowerShell/blob/master/Automate-Module.psm1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...