Files
management-scripts/Install-Scripts.ps1
T
2019-11-11 19:22:39 -05:00

24 lines
1.0 KiB
PowerShell

## Define the scripts and URLs to them
$URLS = @(
'https://emberkom.s3.amazonaws.com/management/scripts/Upload-Contents.ps1'
)
## Define and prepare the main script directory
$SCRIPT_DIRECTORY = "${Env:ProgramData}\Emberkom\Scripts"
if (!(Test-Path $SCRIPT_DIRECTORY)) { New-Item -ItemType Directory -Path $SCRIPT_DIRECTORY }
## Loop through each URL
ForEach ($url in $URLS) {
## Set the script name based on the URL path
$SCRIPT_FILE = $($url.Split('/') | Select-Object -Last 1)
## Delete any previous version of the script
If ( Test-Path "${SCRIPT_DIRECTORY}\${SCRIPT_FILE}" ) {
try { Remove-Item -Path "${SCRIPT_DIRECTORY}\${SCRIPT_FILE}" }
catch { Write-Host "Could not delete ${SCRIPT_DIRECTORY}\${SCRIPT_FILE}"; exit } }
## Download latest version of script
If ( !( Test-Path "${SCRIPT_DIRECTORY}\${SCRIPT_FILE}" )) {
try { (New-Object System.Net.WebClient).DownloadFile($url,"${SCRIPT_DIRECTORY}\${SCRIPT_FILE}") }
catch { Write-Host "Failed to download ${url}" } } }