-1

I have a text file which consists of 100s of URLs. Those URLs again contain different installer files(.exe, .msi, .bat, .txt etc..)

I need to download those files onto my local machine using Invoke-WebRequest. But how can I download files without specifying the extension type of it in the Output path?

File.txt:

https://foo.com/path/to/file.exe?token=ahcdj009a
https://foo.com/path/to/file.msi?token=ansjndhkg
https://foo.com/path/to/file.lpr?token=553dndgbs
https://foo.com/path/to/file.txt?token=amnewa453
...etc        

How do I download all the files from the URLs onto a Windows local machine using Invoke-WebRequest PowerShell command?

1

2 Answers 2

0

If the pattern stays this way (. + file extension + ?), you can use these two lines, while $fileExt is the file extension. Hope it helps a bit :)

$d -match "\.(\w+)\?"
$fileExt = $matches[1]
Sign up to request clarification or add additional context in comments.

Comments

0

You wont want to use just iwr. You will need to use something in addition to that to download the files. Start-BitsTranfer should work.

If you want to download all linked images for example, you can try this:

$URL = "http://www.website.com"

$Site = iwr -Uri $URL

$Images = ($Site).Images.src

foreach ($Image in $Images) {

Start-BitsTransfer -Source $Image -Destination C:\Test\ -TransferType Download

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.