Files
management-scripts/Install-EmberkomCloudBackup.ps1
T

79 lines
4.1 KiB
PowerShell
Raw Normal View History

2023-12-07 12:06:38 -05:00
# Specify URL to "Backup for Windows" agent installer
2026-05-18 16:30:38 -04:00
$ECB_WIN_URL = 'https://console.msp360.com/api/build/download?urlParams=OEFsMzhldm1SbjhaSDhBc2VtYkpUREM3Y2pJSzg0REU4dkVtR1pHREkxMGFFUk9qZXJnSXk5SUF0ei8wZlZOWTBzNG1zVDV0ckVMdStZVzBsam5uZklMVnZLeTBMVmxGNWt4VDhSMzNIL3VNREJWUnRqSWdyb2p0Zk0rMEZNZndoMXB1cW45Mkt2SUJIaXl4WUxxK1ptTno2dWxZRVBHa1NFQ09uWmdiNHlTdG1pYk4waGVDbTdnUFBvZjljaHdud2FLSXlrM2gvZXZCNFM2TEFUTDdIZz09&brandId=fb8308e2-448a-4645-a5f6-a3632a7e57f4'
2021-09-22 14:51:23 -04:00
2022-12-15 13:33:26 -05:00
# Specify URL to "Backup Virtual Machine Edition" agent installer
2026-05-18 16:30:38 -04:00
$ECB_VMM_URL = 'https://console.msp360.com/api/build/download?urlParams=OEFsMzhldm1SbjhaSDhBc2VtYkpUREM3Y2pJSzg0REU4dkVtR1pHREkxMGFFUk9qZXJnSXk5SUF0ei8wZlZOWUpYM2xDY3ErMkpOVGpuWTRISDNFcFRFdWRibDgvTm8vUDhpWndON3kzaHNVc21KTGQ2MW5GZytlelVjaUtscituamdvSGg0NnVmVnluN3dsQkZaU25hN3NIcWxzVWxLODhOcmJXMURBdVR1emZpWWlIK3daWXFjWFhJcno3eUJ3bFlWNEx5Qms4STVZVVJxemxNMHJXZz09&brandId=fb8308e2-448a-4645-a5f6-a3632a7e57f4'
2021-09-22 14:51:23 -04:00
2022-12-15 13:33:26 -05:00
# Set the correct download URL and agent edition
2021-09-22 14:51:23 -04:00
switch ( $Edition.ToLower() ) {
'server' { $URL = $ECB_WIN_URL; $AgentEdition = 'baremetal' }
'desktop' { $URL = $ECB_WIN_URL; $AgentEdition = 'desktop' }
'vm' { $URL = $ECB_VMM_URL; $AgentEdition = 'vmedition' }
default { $URL = $ECB_WIN_URL; $AgentEdition = 'desktop' }
}
2022-12-15 14:18:31 -05:00
# Install and import additional Powershell module
2023-12-07 12:06:38 -05:00
Import-MSP360Module
2024-01-19 21:39:13 -05:00
# Exit this script if the agent is already installed
2024-02-01 11:02:16 -05:00
If ( $(Get-MBSAgent -ErrorAction SilentlyContinue) ) {
2024-01-19 21:39:13 -05:00
Microsoft.Powershell.Utility\Write-Output "Backup agent is already installed. This script will now exit."
Return
}
2023-12-07 12:06:38 -05:00
2024-03-29 11:48:18 -04:00
#
# The URL is now too long to pass as a variable to other functions and cmdlets, so this is a workaround to download the file
#
# Make sure the URL is valid
$StatusCode = [System.Net.WebRequest]::Create($URL).GetResponse().StatusCode
If ( !(($StatusCode -ge 200) -and ($StatusCode -lt 400)) ) { Write-Output "URL cannot be reached (status code ${StatusCode}): ${URL}" ; Return }
# Make a local file to download to
$Installer = '{0}EmberkomCloudBackup.exe' -f (Get-TempPath)
# Delete previous local file if it exists
2024-03-29 11:51:34 -04:00
If ( Test-Path $Installer ) { Write-Output "Deleting previously downloaded file: ${Installer}" ; Remove-Item $Installer -Force -ErrorAction SilentlyContinue }
2024-03-29 11:48:18 -04:00
# Download the file
2024-03-29 11:51:34 -04:00
Try { (New-Object System.Net.WebClient).DownloadFile($URL,$Installer) }
Catch { Write-Error $_.Exception.Message ; Remove-Item $Installer -Force -ErrorAction SilentlyContinue }
2024-03-29 11:48:18 -04:00
# Make sure the file exists
2024-03-29 11:51:34 -04:00
If ( !(Test-Path $Installer) ) { Write-Output "There was a problem downloading the file, this script will not continue" ; Return }
2024-03-29 11:48:18 -04:00
#
# End the workaround
#
2024-02-01 11:02:16 -05:00
2024-01-19 21:39:13 -05:00
# Install the agent
Write-Output "Installing Emberkom Cloud Backup agent"
Try { Start-Process "${Installer}" -ArgumentList "/S" -Wait }
Catch { Write-Error $_.Exception.Message }
2024-02-01 11:02:16 -05:00
2024-01-19 21:39:13 -05:00
# Add backup user to installed product
2024-02-01 11:02:16 -05:00
Write-Output "Adding backup user account: ${MSP360Username}"
Try { Add-MBSUserAccount -User $MSP360Username -Password $(ConvertTo-SecureString -string $MSP360Password -AsPlainText -Force) }
2024-01-19 21:39:13 -05:00
Catch { Write-Error $_.Exception.Message }
2024-02-01 11:02:16 -05:00
2024-01-19 21:39:13 -05:00
# Wait a few seconds to let the agent check-in
Start-Sleep -Seconds 10
2024-02-01 11:02:16 -05:00
2024-01-19 21:39:13 -05:00
# Set the agent edition
# Note: the product edition must be set *after* the user is added
Write-Output "Setting Emberkom Cloud Backup agent edition to ""$AgentEdition"""
Try {
Switch ([string]::IsNullOrEmpty($MasterPassword)) {
$true { Set-MBSAgentSetting -Edition $AgentEdition -Verbose }
2024-02-01 11:02:16 -05:00
$false { Set-MBSAgentSetting -Edition $AgentEdition -MasterPassword $(ConvertTo-SecureString -String $MasterPassword -AsPlainText -Force) -Verbose }
}
}
2024-01-19 21:39:13 -05:00
Catch { Write-Error $_.Exception.Message }
2021-10-08 05:41:49 -04:00
2024-03-29 11:48:18 -04:00
# Delete $Installer
If ( Test-Path $Installer ) { Write-Output "Deleting downloaded file: ${Installer}" ; Remove-Item $Installer -Force -ErrorAction SilentlyContinue }
2022-12-15 13:33:26 -05:00
# Delete the desktop icon
2023-12-07 12:06:38 -05:00
If ( Test-Path "${Env:PUBLIC}\Desktop\Emberkom Backup.LNK" ) { Remove-Item -Path "${Env:PUBLIC}\Desktop\Emberkom Backup.LNK" -Force -ErrorAction SilentlyContinue }
If ( Test-Path "${Env:PUBLIC}\Desktop\Emberkom Cloud Backup.LNK" ) { Remove-Item -Path "${Env:PUBLIC}\Desktop\Emberkom Cloud Backup.LNK" -Force -ErrorAction SilentlyContinue }