added restore settings from previous install

This commit is contained in:
2022-04-15 13:26:29 -04:00
parent d5e40c15a1
commit 28bc9436ed
+28 -9
View File
@@ -5,9 +5,6 @@
[Parameter(Mandatory=$false)][switch]$FORCE
)
# Replace the '@' with '%40' - not sure why this is necessary, but it is
$INTEGRATOR_ID = $INTEGRATOR_ID.Replace('@','%40')
# Source the Tools.ps1 script
Function SourceTools
{ . $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1'))) }
@@ -26,14 +23,25 @@ If ( $INSTALL ) {
# Uninstall if $FORCE is true
If ( $PreviousInstall ) {
LogMsg "Uninstalling previously installed agent"
$UninstallScript = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Uninstall-AteraAgent.bat'
Try { Start-Process "cmd.exe" -ArgumentList "/c ""${UninstallScript}""" -Wait }
Catch { LogErr $_.Exception.Message }
Try { Remove-Item $UninstallScript -Force }
Catch { LogErr $_.Exception.Message }
# Get previous AccountID, AgentID, CompanyID, and IntegratorID for use when reinstalling
LogMsg "Getting information from existing installation"
$ACCOUNT_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AccountId' -ErrorAction SilentlyContinue)
$AGENT_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AgentId' -ErrorAction SilentlyContinue)
$CUSTOMER_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'CompanyId' -ErrorAction SilentlyContinue)
$INTEGRATOR_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'IntegratorLogin' -ErrorAction SilentlyContinue)
LogMsg "Uninstalling previously installed agent"
Run-Script -LivePSScript Uninstall-AteraAgent
# $UninstallScript = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Uninstall-AteraAgent.ps1'
# Try { Start-Process "powrshell.exe" -ArgumentList "-ExecutionPolicy Bypass -InputFormat None -NonInteractive -File ""${UninstallScript}""" -Wait }
# Catch { LogErr $_.Exception.Message }
# Try { Remove-Item $UninstallScript -Force }
# Catch { LogErr $_.Exception.Message }
}
# Replace the '@' with '%40' - not sure why this is necessary, but it is
$INTEGRATOR_ID = $INTEGRATOR_ID.Replace('@','%40')
# Download agent installer
Download-File -URL "https://app.atera.com/GetAgent/Msi/?customerId=${CUSTOMER_ID}&integratorLogin=${INTEGRATOR_ID}" -File "${AGENT_INSTALLER}"
@@ -47,6 +55,17 @@ If ( $INSTALL ) {
Try { Remove-Item $AGENT_INSTALLER -Force }
Catch { LogErr $_.Exception.Message }
# Restore agent information from previous install
If ( $PreviousInstall ) {
LogMsg "Stopping AteraAgent service"
Stop-Service -Name 'AteraAgent' -Force
LogMsg "Restoring AgentID and AccountID from previous install"
Set-ItemProperty -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AccountId' -Value $ACCOUNT_ID
Set-ItemProperty -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AgentId' -Value $AGENT_ID
LogMsg "Starting AteraAgent service"
Start-Service -Name 'AteraAgent'
}
} Else { LogMsg "Atera agent is already installed on this endpoint." }
# Delete this script