added restore settings from previous install
This commit is contained in:
+28
-9
@@ -5,9 +5,6 @@
|
|||||||
[Parameter(Mandatory=$false)][switch]$FORCE
|
[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
|
# Source the Tools.ps1 script
|
||||||
Function SourceTools
|
Function SourceTools
|
||||||
{ . $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1'))) }
|
{ . $([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
|
# Uninstall if $FORCE is true
|
||||||
If ( $PreviousInstall ) {
|
If ( $PreviousInstall ) {
|
||||||
LogMsg "Uninstalling previously installed agent"
|
# Get previous AccountID, AgentID, CompanyID, and IntegratorID for use when reinstalling
|
||||||
$UninstallScript = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Uninstall-AteraAgent.bat'
|
LogMsg "Getting information from existing installation"
|
||||||
Try { Start-Process "cmd.exe" -ArgumentList "/c ""${UninstallScript}""" -Wait }
|
$ACCOUNT_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AccountId' -ErrorAction SilentlyContinue)
|
||||||
Catch { LogErr $_.Exception.Message }
|
$AGENT_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AgentId' -ErrorAction SilentlyContinue)
|
||||||
Try { Remove-Item $UninstallScript -Force }
|
$CUSTOMER_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'CompanyId' -ErrorAction SilentlyContinue)
|
||||||
Catch { LogErr $_.Exception.Message }
|
$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 agent installer
|
||||||
Download-File -URL "https://app.atera.com/GetAgent/Msi/?customerId=${CUSTOMER_ID}&integratorLogin=${INTEGRATOR_ID}" -File "${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 }
|
Try { Remove-Item $AGENT_INSTALLER -Force }
|
||||||
Catch { LogErr $_.Exception.Message }
|
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." }
|
} Else { LogMsg "Atera agent is already installed on this endpoint." }
|
||||||
|
|
||||||
# Delete this script
|
# Delete this script
|
||||||
|
|||||||
Reference in New Issue
Block a user