add module download image using jobs
This commit is contained in:
parent
bcae4dfa7b
commit
b5c6cfddc7
1 changed files with 31 additions and 0 deletions
31
Scripts/Download-Image.psm1
Normal file
31
Scripts/Download-Image.psm1
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
function Download-Image {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory = $True)]$url
|
||||||
|
)
|
||||||
|
$folder = $url -replace "http.+://" -replace "/","-" -replace "-$"
|
||||||
|
$path = "$home\Pictures\$folder"
|
||||||
|
if (Test-Path $path) {
|
||||||
|
Remove-Item $path -Recurse -Force
|
||||||
|
New-Item -ItemType Directory $path > $null
|
||||||
|
} else {
|
||||||
|
New-Item -ItemType Directory $path > $null
|
||||||
|
}
|
||||||
|
$irm = Invoke-WebRequest -Uri $url
|
||||||
|
foreach ($img in $irm.Images.src) {
|
||||||
|
$name = $img -replace ".+/"
|
||||||
|
Start-Job {
|
||||||
|
Invoke-WebRequest $using:img -OutFile "$using:path\$using:name"
|
||||||
|
} > $null
|
||||||
|
}
|
||||||
|
while ($True){
|
||||||
|
$status_job = (Get-Job).State[-1]
|
||||||
|
if ($status_job -like "Completed"){
|
||||||
|
Get-Job | Remove-Job -Force
|
||||||
|
break
|
||||||
|
}}
|
||||||
|
$count_all = $irm.Images.src.Count
|
||||||
|
$count_down = (Get-Item $path\*).count
|
||||||
|
"Downloaded $count_down of $count_all files to $path"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download-Image -url https://losst.pro/
|
||||||
Loading…
Add table
Add a link
Reference in a new issue