Created
December 24, 2022 05:40
-
-
Save arcanisgk/ace898aef6423650cdea73e4ad6024b5 to your computer and use it in GitHub Desktop.
This file contains 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
$srcfile = "C:\Users\wnune\OneDrive\Escritorio\imagenes\cardlist.txt" | |
$urls = Get-Content $srcfile | |
$lines = 0 | |
switch -File $srcfile { default { ++$lines } } | |
$i = 0 | |
$urls | | |
ForEach-Object -Parallel { | |
try { | |
$url = $_ | |
$filename = Split-Path $url -Leaf | |
$destination = "C:\Users\wnune\OneDrive\Escritorio\imagenes\$filename" | |
$ProgressPreference = 'SilentlyContinue' | |
$response = Invoke-WebRequest -Uri $url -ErrorAction SilentlyContinue | |
if ($response.StatusCode -ne 200) { | |
Write-Warning "=============================================" | |
Write-Warning "Url $url return Error. " | |
continue | |
} | |
if (Test-Path $destination) { | |
Write-Warning "=============================================" | |
Write-Warning "File Exist in Destination: $filename " | |
continue | |
} | |
$job = Start-BitsTransfer -Source $url -Destination $destination -Asynchronous | |
while (($job | Get-BitsTransfer).JobState -eq "Transferring" -or ($job | Get-BitsTransfer).JobState -eq "Connecting") | |
{ | |
Start-Sleep -m 250 | |
} | |
Switch(($job | Get-BitsTransfer).JobState) | |
{ | |
"Transferred" { | |
Complete-BitsTransfer -BitsJob $job | |
} | |
"Error" { | |
$job | Format-List | |
} | |
} | |
} | |
catch | |
{ | |
Write-Warning "=============================================" | |
Write-Warning "There was an error Downloading" | |
Write-Warning "url: $url" | |
Write-Warning "file: $filename" | |
Write-Warning "Exception Message:" | |
Write-Warning "$($_.Exception.Message)" | |
} | |
} | | |
ForEach-Object { | |
[int] $percent = ((++$i / $using.lines) * 100) | |
Write-Host -ForegroundColor Yellow -NoNewLine ("`r{0,3}% complete" -f $percent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment