If I run a single line with the command prompt, it works. But when I create a bat-file to run all the lines in a row, it always comes up with error “404 Not found”.
(It is the same when I run a single line with Powershell as opposed to running the whole list as a ps1-script).
How can I use command prompt or powershell to run the whole list?
No need for batch files, it would be best to convert your site and file names into a csv (or other format) to be consumed as an object from Powershell. CSV is the most straight forward and you can use Import-Csv in place of the $csv that is mocking the import of a csv. The use a loop to enumerate the CSV and process each row. Here is a basic example:
Processing https://theswissbay.ch/xy.pdf and exporting to e:\xy.pdf
Processing https://foo.com/foo.pdf and exporting to e:\foo.pdf
Would recommend adding try\catch and setting the ErrorAction on the Invoke-Restmethod so that you can track if a specific site is giving a 404 so you can fix it.
By the way, I found out why it doesn’t work with the batch-file - which of course would be the easiest solution: because here some characters are encoded in the form $hx, and when reading from a file the command prompt ignores the % character. So you would have to convert e.g. every occurrence of %20 (=ascii 32) within a link into a space etc.