Created
June 9, 2015 14:27
-
-
Save ploegert/afa5f29b308806027ddd to your computer and use it in GitHub Desktop.
Downloads a file from a url and outputs the path to the file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Downloads the given URL to a local file and outputs the path to the file | |
| # | |
| function Download | |
| { | |
| param([Parameter(Mandatory=$true)][string] $Url) | |
| $webClient = $null | |
| try | |
| { | |
| $uri = [URI] $url | |
| $update = $uri.Segments[$uri.Segments.Count - 1] | |
| $localFile = '{0}\{1}' -f $DSC_MainWorkingFolder, $update | |
| if (Test-Path $localFile) { | |
| throw New-HandlerTerminatingError ` | |
| -Code $DSC_Status.WmfInstallError.Code ` | |
| -Message ($DSC_Status.WmfInstallError.Message -f $update, (GetLogDirectory)) | |
| } | |
| Write-Log "Downloading $Url ..." | |
| $webClient = New-Object System.Net.WebClient | |
| $webClient.DownloadFile($Url, $localFile) | |
| $localFile | |
| } | |
| finally | |
| { | |
| if ($webClient) { | |
| $webClient.Dispose() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment