Skip to main content

PowerShell function to download a file from a given URL and store it in the specified local target path.

#
# Download a file from a URL and place it at the specified target path. This
# also has some basic capabilities to go through proxies without any additional
# configuration.
function Power-Curl($TargetPath, $SourceUrl)
{
    try
    {
        $webclient = New-Object System.Net.WebClient
        $webclient.DownloadFile($SourceUrl, $TargetPath)
    }
    catch
    {
        Write-Host -ForegroundColor Red "$_ occurred while downloading $SourceUrl to $TargetPath"
        $_ | fl * -Force
    }
}

#
# Example usage:
#

$baseDir = Resolve-Path ..
$srcdir = "$baseDir\src";

# Download the core profiles for code generation
Power-Curl "$srcdir\Hl7.Fhir.Core\Model\Source\expansions.xml" "http://hl7-fhir.github.io/expansions.xml"