I'm trying to download multiple PDFs from URLs using invoke-webrequest. I also want the PDFs to have unique names (that I choose) but to be downloaded into a single folder.
This is what I've got so far (for 1 url):
invoke-webrequest -uri "https://www.website.com/fact.pdf" -Outfile $env:TEMPC:\Users\MyPC\Downloads\TEST.pdf
PS; this is literally my first time using powershell and do not have a clue
EDIT: Thanks - was exactly what I was after.
I am wondering if you would be able to help me further. I've to download these PDFs from these URLs on a daily basis. I would already have the previous day's PDFs downloaded, so am now looking to see if I could run a script where:
- create an 'archive' folder and move previous day's pdfs (which would be located in different folders) into said folder
- to have unique names for new PDFs (you have already shown me this using hashtable)
- to download PDFs from the URLs, but place them in different locations e.g. 'TEST.pdf' to go to C:\Users\MyPC\Downloads\PDFs\Short and 'ANOTHER.pdf' to go to C:\Users\MyPC\Downloads\PDFs\Long and so on...
Organize your URLs and their target file names in a hashtable:
Now you just need to repeat the
Invoke-WebRequest
for each entry in the hashtable: