File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -703,3 +703,73 @@ function GetAzureStackBlobUri
703703 throw $_.Exception.Message
704704 }
705705}
706+
707+ function DownloadFile
708+ {
709+ param
710+ (
711+ [Parameter (Mandatory = $true )]
712+ [String ] $FileUrl ,
713+ [Parameter (Mandatory = $true )]
714+ [String ] $OutputFolder
715+ )
716+ $retries = 20
717+ $lastException = $null
718+ $success = $false
719+
720+ while ($success -eq $false -and $retries -ge 0 )
721+ {
722+ $success = $true
723+ try
724+ {
725+ $outputFile = Join-Path $OutputFolder (Split-Path - Path $FileUrl - Leaf)
726+ $wc = New-Object System.Net.WebClient
727+ $wc.DownloadFile ($FileUrl , $outputFile ) | Out-Null
728+ }
729+ catch
730+ {
731+ $success = $false
732+ $lastException = $_
733+ }
734+ $retries --
735+ if ($success -eq $false )
736+ {
737+ Start-Sleep - Seconds 10
738+ }
739+ }
740+
741+ if ($success -eq $false )
742+ {
743+ Write-Output " Timed out trying to download $FileUrl "
744+ throw $lastException
745+ }
746+
747+ return $outputFile
748+ }
749+
750+ function CopyImage
751+ {
752+ param
753+ (
754+ [Parameter (Mandatory = $true )]
755+ [String ] $ImagePath ,
756+ [Parameter (Mandatory = $true )]
757+ [String ] $OutputFolder
758+ )
759+
760+ if (Test-Path $ImagePath )
761+ {
762+ Copy-Item $ImagePath $OutputFolder
763+ $outputfile = Join-Path $OutputFolder (Split-Path $ImagePath - Leaf)
764+ }
765+ elseif ($ImagePath.StartsWith (" http" ))
766+ {
767+ $outputfile = DownloadFile - FileUrl $ImagePath - OutputFolder $OutputFolder
768+ }
769+ if (([System.IO.FileInfo ]$outputfile ).Extension -eq " .zip" )
770+ {
771+ Expand-Archive - Path $outputfile - DestinationPath $OutputFolder - Force
772+ }
773+
774+ return (Get-ChildItem - Path $OutputFolder - File | Where-Object {$_.Extension -eq " .vhd" -or $_.Extension -eq " .vhdx" })[0 ].FullName
775+ }
You can’t perform that action at this time.
0 commit comments