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

If you want to force it to Rip & Replace, change $ForceRip = $True. 

 

Requirements:
• Automate FQDN
• Location ID

 

#!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 }

2019-04-11 - Replaced newer uninstaller | Save Transcript to C:\Windows\Temp

Edited by Braingears
Update Script
  • Like 1

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

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