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