From 75d2f83d3a6c0ba58541616a3ab1273e315b6095 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 29 Mar 2024 11:48:18 -0400 Subject: [PATCH] workaround for long url --- Install-EmberkomCloudBackup.ps1 | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Install-EmberkomCloudBackup.ps1 b/Install-EmberkomCloudBackup.ps1 index 44d8778..bb6ca0b 100644 --- a/Install-EmberkomCloudBackup.ps1 +++ b/Install-EmberkomCloudBackup.ps1 @@ -21,8 +21,30 @@ If ( $(Get-MBSAgent -ErrorAction SilentlyContinue) ) { Return } -# Download the installer -$Installer = Download-File -URL $URL +# +# 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 +If ( Test-Path $File ) { Write-Output "Deleting previously downloaded file: ${File}" ; Remove-Item $File -Force -ErrorAction SilentlyContinue} + +# Download the file +Try { (New-Object System.Net.WebClient).DownloadFile($URL,$File) } +Catch { Write-Error $_.Exception.Message ; Remove-Item $File -Force -ErrorAction SilentlyContinue } + +# Make sure the file exists +If ( !(Test-Path $File) ) { Write-Output "There was a problem downloading the file, this script will not continue" ; Return } + +# +# End the workaround +# # Install the agent Write-Output "Installing Emberkom Cloud Backup agent" @@ -48,6 +70,9 @@ Try { } Catch { Write-Error $_.Exception.Message } +# Delete $Installer +If ( Test-Path $Installer ) { Write-Output "Deleting downloaded file: ${Installer}" ; Remove-Item $Installer -Force -ErrorAction SilentlyContinue } + # Delete the desktop icon 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 }