Jump to content
Braingears

Automate Install - Rip & Replace - Powershell

Recommended Posts

This PowerShell script will automatically check if Automate is installed. It compares if the Automate server is yours, if not, download the Windows Agent Uninstaller, remove any existing instance of an existing Automate agent (from any MSP); then download the .MSI and reinstall the agent to your Automate server. Although it defaults to the 'New Computers' location, you can specify any Location ID to place the computers into. 

The script can be run manually on the client computer, from Control (aka ScreenConnect) Commands, or from Automate scripting using the Execute function (if you are performing a migration to another Automate server).

 

These are the current deployment command scripts. The PowerShell Modules are pulled and maintained from GitHub:
Don't forget to replace your Automate Server FQDN and LocationID in the commands below. 

CMD (as Admin)
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "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 -Transcript"

PowerShell (as Admin)
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 -Transcript

In ScreenConnect / Control
#!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 -Transcript

 

Below is the original script used and referenced (when this post was initially created). This can still be used if you don't feel comfortable using PowerShell Modules maintained in GitHub.

Requirements:
• Automate FQDN
• Location ID
If you want to force it to Rip & Replace, change $ForceRip = $True. 

#!ps
#timeout=900000
#maxlength=9000000
$FQDN = 'YOURSERVER.hostedrmm.com'                   # Enter Automate Server FQDN - Example: 'company.hostedrmm.com' - Leave out HTTP:\\ or HTTPS:\\
$LocationID = '1'                                    # Enter Location ID to place the computer in assigned Client's Location (Location ID '1' = New Computers)
$SoftwarePath = "C:\Support\Automate"                # Enter Software Path in order to download the files to - Example: "C:\Support\Automate"
$ForceRip = $False                                   # Force Agent Uninstall / Install even if agent is already installed and checking into your server ($True or $False)
& {Start-Transcript -Path "$($env:windir)\Temp\AutomateLogon.txt" -Force
    $AutomateURL = "HTTPS://$($FQDN)" 
    $AutomateSrvAddrReg = (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service" -ErrorAction SilentlyContinue).'Server Address'
    $AutomateCompIDReg = (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service" -ErrorAction SilentlyContinue).ID
    if (($AutomateSrvAddrReg -like "*$($FQDN)*") -and ($AutomateCompIDReg -ne $null) -and ($ForceRip -ne $True)) {
        Start-Service ltservice,ltsvcmon -PassThru
        Write-Host ""
        Write-Host "The Automate Agent is already installed." -ForegroundColor Green
        Write-Host "The Automate Agent is checking-in to: $($AutomateSrvAddrReg)" -ForegroundColor Green
        Write-Host "ComputerID: $($AutomateCompIDReg)" -ForegroundColor Green 
        Write-Host " "
        } else {
    # Remove Existing Automate Agent
        if (Test-Path "$($env:windir)\ltsvc") {
        $DownloadPath = "https://s3.amazonaws.com/assets-cp/assets/Agent_Uninstall.exe"
        $Filename = [System.IO.Path]::GetFileName($DownloadPath)
        $SoftwareFullPath = "$($SoftwarePath)\$Filename"
        $wc = New-Object System.Net.WebClient
        if (!(Test-Path $SoftwarePath)) {md $SoftwarePath}
        Set-Location $SoftwarePath
        if ((Test-Path $SoftwareFullPath)) {Remove-Item $SoftwareFullPath}
        $wc.DownloadFile($DownloadPath, $SoftwareFullPath)
        Write-Host "Removing existing Automate Agent..."
        Stop-Process -Name "ltsvcmon","lttray","ltsvc","ltclient" -Force -PassThru -ErrorAction SilentlyContinue
        Stop-Service ltservice,ltsvcmon -Force -ErrorAction SilentlyContinue
        cmd /c $SoftwareFullPath
        Write-Host " "
        Write-Host "Waiting 60 seconds to continue..." -ForegroundColor Gray
        Start-Sleep 60
            if (Test-Path "$($env:windir)\ltsvc\lterrors.txt") {
            Write-Host "  still waiting..." -ForegroundColor Gray
            Start-Sleep 90}
            if (Test-Path "$($env:windir)\ltsvc\lterrors.txt") {
            Write-Host "$($env:windir)\LTSVC folder still exists" -ForegroundColor Red} else {
            Write-Host "The Automate Agent Removed Successfully" -ForegroundColor Green
            Write-Host " "
            }}
    # Install Automate Agent
        $DownloadPath2 = "$($AutomateURL)/Labtech/Deployment.aspx?Probe=1&installType=msi&MSILocations=$($LocationID)"
        $Filename2 = "AutomateAgent.msi"
        $SoftwareFullPath2 = "$SoftwarePath\$Filename2"
        if (!(Test-Path $SoftwarePath)) {md $SoftwarePath}
        Set-Location $SoftwarePath
        if ((test-path $SoftwareFullPath2)) {remove-item $SoftwareFullPath2}
        $wc = New-Object System.Net.WebClient
        $wc.DownloadFile($DownloadPath2, $SoftwareFullPath2)
        Write-Host "Installing Automate Agent on $($AutomateURL)" -ForegroundColor Yellow
        Stop-Process -Name "ltsvcmon","lttray","ltsvc","ltclient" -Force -PassThru -ErrorAction SilentlyContinue
        msiexec.exe /i $($SoftwareFullPath2) /quiet /norestart LOCATION=$($LocationID)
        Start-Sleep -s 15
        # Installer will execute twice (KI 12002617)
        msiexec.exe /i $($SoftwareFullPath2) /quiet /norestart LOCATION=$($LocationID)
        Write-Host "Waiting 3 minutes for Automate to install..." -ForegroundColor Gray
        Start-Sleep -s 180
        Write-Host "Starting Automate Services..." -ForegroundColor Yellow
        Start-Service ltservice,ltsvcmon -PassThru
        $AutomateSrvAddrReg = (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service" -ErrorAction SilentlyContinue).'Server Address'
        $AutomateCompIDReg = (Get-ItemProperty "HKLM:\SOFTWARE\LabTech\Service" -ErrorAction SilentlyContinue).ID
            if (($AutomateSrvAddrReg -like "*$($FQDN)*") -and ($AutomateCompIDReg -ne $null)) {
            Write-Host " "
            Write-Host "The Automate Agent is checking-in to:" -ForegroundColor Green
            Write-Host "$($AutomateSrvAddrReg)" -ForegroundColor Green
            Write-Host "ComputerID: $($AutomateCompIDReg)" -ForegroundColor Green 
            Write-Host " "
            } else {
                Write-Host " "
                Write-Host "The Automate Agent is NOT installed and/or checking-in" -ForegroundColor Red
                Write-Host "Server Address: $($AutomateSrvAddrReg)" -ForegroundColor Yellow
                Write-Host "ComputerID: $($AutomateCompIDReg)" -ForegroundColor Yellow
                Write-Host " "
            }}
  Stop-Transcript }

2020-06-10 - Added the newer replacement commands here in the initial post. 
2019-04-11 - Replaced newer uninstaller | Save Transcript to C:\Windows\Temp

Edited by Braingears
Update Commands
  • Like 2

Share this post


Link to post
Share on other sites

Thanks for posting this up!

You may well benefit from knowing about the LabTech Powershell Module out there in the wild. http://labtechconsulting.com/labtech-agent-powershell-module/

The module is on Github and is primarily maintained by the below, I'm sure they'd appreciate additional contributions! What I really like about that method is you can just call it from anywhere with an internet connection, the below, for example, would Reinstall the agent with no additional dependencies needed:

(new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | iex

 

@CTaylor and @DarrenWhite99

  • Thanks 1

Share this post


Link to post
Share on other sites
56 minutes ago, Gavsto said:

Thanks for posting this up!

You may well benefit from knowing about the LabTech Powershell Module out there in the wild. http://labtechconsulting.com/labtech-agent-powershell-module/

The module is on Github and is primarily maintained by the below, I'm sure they'd appreciate additional contributions! What I really like about that method is you can just call it from anywhere with an internet connection, the below, for example, would Reinstall the agent with no additional dependencies needed:


(new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | iex

 

@CTaylor and @DarrenWhite99

Since you have to customize the script with your Automate server's FQDN and 'System Password', it cannot be called and run on demand from a public / generic source. 

Share this post


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

Since you have to customize the script with your Automate server's FQDN and 'System Password', it cannot be called and run on demand from a public / generic source. 

It can - ie the following would work:

(new-object Net.WebClient).DownloadString('http://bit.ly/ltposh') | iex; Reinstall-LTService -Server https://yourrmm.yourdomain.com -Password whateveritis


 

Share this post


Link to post
Share on other sites

 

I found that older computers such as Windows 2003 Server did not download the files using the HTTPS links, but would work with HTTP; so I've revised the script accordingly. I've also added the capability to target the Location ID the computers are placed into.

 

Edited by Braingears

Share this post


Link to post
Share on other sites

Update to verify if YOUR agent is already installed. If it's from another MSP, it will replace it with yours.

Edited by Braingears

Share this post


Link to post
Share on other sites

I am replacing this script with my new Install-Automate Functions that I've placed on GitHub:
https://docs.connectwise.com/ConnectWise_Automate/ConnectWise_Automate_Documentation/070/175

CMD (as Admin)
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Command "Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.ps1'); Install-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2"

PowerShell (as Admin)
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.ps1'); Install-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2

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


Examples:
# Install Automate 
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.ps1'); Install-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Transcript
# Force Rip & Replace of Automate Agent
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.ps1'); Install-Automate -Server 'YOURSERVER.DOMAIN.COM' -LocationID 2 -Force -Transcript
# Check if Automate is installed and checking in 
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.ps1'); Confirm-Automate -Show
# Show Automate registry key
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.ps1'); Confirm-Automate -Raw


Functions:
Confirm-Automate
Uninstall-Automate
Install-Automate

 

  • Thanks 1

Share this post


Link to post
Share on other sites

I have updated GitHub with Push-Automate in the Automate Functions.

 

Edited by Braingears
Use GitHub for up-to-date Auto-Module
  • Like 2

Share this post


Link to post
Share on other sites

I'm getting stuck on Exit Code: 1612 running the PS Script.

There's some endpoints that still have remnants of LT or Automate agents still so the install through PS, CMD fail. Anyway to add a ForceUninstall-Automate where it will download the Uninstaller anyway and run it even if it doesn't detect an installation of it?

I'm an idiot. I see it from the notes -Force for the win.

Edited by spilgrim
I'm an idiot

Share this post


Link to post
Share on other sites

# Uninstall Automate Agent
Invoke-Expression(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Braingears/PowerShell/master/Automate-Module.psm1'); Uninstall-Automate -Force

Share this post


Link to post
Share on other sites

It depends on a hidden setting. If the Mac Signup is set to "-1", when Automate identifies a computer with the same MAC address, it will reassign the already existing ComputerID instead of creating a new one. 

Automate Control Center > Help > Server Status

image.png.170109a2cde10c1efc4741bef62b0fb4.png

There is a hidden menu is you double-click on the bottom line (I always double-click on the word servers)

image.png.92b76c971b1785136e3e6b8214158868.png

In the "Mac Signup Time Limit" enter:  -1

Click "Save and Restart DBAgent" (I don't know if restarting the DBAgent is needed, but it's what I do because so many things in Automate are cached). 

 

If you have SQL access, you can use: 

UPDATE `lt_web_servers_config` SET MacSignUpTimeLimit = -1;

 

Share this post


Link to post
Share on other sites

The Mac Signup Time Limit was already set to -1.  And it is not a setting I would have touched (I'm the only one using Automate over here), so it was -1 at the time of the Force Rip and Replace.

Share this post


Link to post
Share on other sites
On 3/13/2020 at 2:26 PM, axiomcrs2 said:

The Mac Signup Time Limit was already set to -1.  And it is not a setting I would have touched (I'm the only one using Automate over here), so it was -1 at the time of the Force Rip and Replace.

Are you having an issue?

Share this post


Link to post
Share on other sites

You said that if the Mac Signup Limit was set to -1 then the Force Rip and Replace will reuse the original agent id.  Well mine was set to -1 and the Force Rip and Replace did not reuse the agent id, but created a new one.

Share this post


Link to post
Share on other sites
15 hours ago, axiomcrs2 said:

You said that if the Mac Signup Limit was set to -1 then the Force Rip and Replace will reuse the original agent id.  Well mine was set to -1 and the Force Rip and Replace did not reuse the agent id, but created a new one.

How many duplicates have you experienced? Is this unique to one computer, or is this happening every time you R&R?

Share this post


Link to post
Share on other sites

Can you touch on the Failure error of: "The Automate Server Parameter Was Not Entered or Inaccessable"    (might want to check the spelling - Inaccessible)

Help: Get-Help Install-Automate -Full

 

Thanks

Share this post


Link to post
Share on other sites
Posted (edited)

Thank you for the spelling correction within the help section. If that's the only error, then I'm still pretty happy with the module. 

I am currently testing a GitHub Branch of the script that's more aggressive when the Uninstaller leaves pieces behind (specifically the registry keys). I will include the update the next time I update the Master. 

Edited by Braingears

Share this post


Link to post
Share on other sites

@Braingears thank you so much for the script.

Waiting for your new Master version with more aggressive uninstalling since I have several computers with this: 

 

Transcript started, output file is C:\windows\Temp\Automate_Deploy.txt
Removing Existing Automate Agent...
The Automate Agent Uninstalled Successfully
Automate is NOT Installed
Installing Automate Agent to http://.....com
Automate Installer Exit Code: 1603
Automate Installer Logs: C:\windows\Temp\Automate_Agent_2020-05-05_09-58-34.log
The Automate MSI failed. Waiting 15 Seconds...
Installer will execute twice (KI 12002617)
Automate Installer Exit Code: 1603
Automate Installer Logs: C:\windows\Temp\Automate_Agent_2020-05-05_09-58-51.log
Transcript stopped, output file is C:\windows\Temp\Automate_Deploy.txt

 

And I have others with just:

Transcript started, output file is C:\Windows\Temp\Automate_Deploy.txt
Removing Existing Automate Agent...
The Automate Agent Uninstalled Successfully
Automate is NOT Installed
Installing Automate Agent to https://.....com
Transcript stopped, output file is C:\Windows\Temp\Automate_Deploy.txt

 

Do you think your new version can help with that?

 

Thank you!

Share this post


Link to post
Share on other sites

@Braingears I think I've found the solution for the following error:

 

Automate Installer Exit Code: 1603
Automate Installer Logs: C:\windows\Temp\Automate_Agent_2020-05-12_23-40-53.log
The Automate MSI failed. Waiting 15 Seconds...
Installer will execute twice (KI 12002617)
Automate Installer Exit Code: 1603
Automate Installer Logs: C:\windows\Temp\Automate_Agent_2020-05-12_23-41-10.log
Transcript stopped, output file is C:\windows\Temp\Automate_Deploy.txt

 

I've run a CMD file (attached here) I had to fully uninstall LabTech agent. Not sure which of the registry keys that my script deleted make your script worked again, but this procedure is fully tested on several machines with Windows 7 and Windows 10.

If I run your script and get the mentioned error, then run the CMD and then your script again and is 100% working.

Do you think you can get the commands from the CMD and update your uninstall method?

Thank you  

1 - Uninstall LT Agent.cmd

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...