. "$PSScriptRoot/Context.ps1"; function Install-SoftwarePackage([Context] $context, [string] $location, [string[]] $argumentList = @("/S"), [switch]$local) { [string]$filePath = ""; [string]$tempDir = $null; if (-not ($local.IsPresent)) { Write-Information "Determining the file name of $location"; $tempDir = $context.GetTempDirectory(); $request = [System.Net.WebRequest]::Create($location); $request.AllowAutoRedirect = $false; $response = $request.GetResponse(); $fileName = [System.IO.Path]::GetFileName($response.GetResponseHeader("Location")); Write-Information "$fileName"; $filePath = Join-Path $tempDir $fileName; Write-Information "Downloading setup file from $location"; Invoke-WebRequest $location -OutFile $filePath; } else { $filePath = $location; } $fileName = [System.IO.Path]::GetFileName($filePath); Write-Information "Starting installation of $fileName"; Start-Process -Wait -FilePath $filePath -ArgumentList $argumentList; if ($tempDir) { Remove-Item -Recurse $tempDir; } }