 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to download images using Invoke-Webrequest in PowerShell?
To download the images from the webpage using the Invoke-WebRequest command, we can use the images property from the result to retrieve the images URL, and later we can use the method to download them at the specific location. Consider we have the URI: https://theautomationcode.com to retrieve the images.
Once you run the below command, you can see the Images property there.
Invoke-WebRequest -Uri "https://theautomationcode.com/feed/"
To retrieves the images URL,
$req = Invoke-WebRequest -Uri "https://theautomationcode.com/feed/" $req.Images | Select -ExpandProperty src
Output
https://i1.wp.com/theautomationcode.com/wp-content/uploads/2020/11/image-9.png?resize=178%2C60&ssl=1 https://i0.wp.com/theautomationcode.com/wp-content/uploads/2020/11/image-10.png?resize=640%2C68&ssl=1
All the above URLs point to the images, so we can download that.
$wc = New-Object System.Net.WebClient $req = Invoke-WebRequest -Uri "https://theautomationcode.com/feed/" $images = $req.Images | Select -ExpandProperty src $count = 0 foreach($img in $images){        $wc.DownloadFile($img,"C:\Temp\WebImages\img$count.jpg") } The output images will be stored in the C:\temp\WebImages folder.
Advertisements
 