Modifying PowerShell script to automate download of

I had this question after viewing Powershell to download file from series of URL.

Hi All,

Can anyone please assist me with the below PowerShell Script that I can use to test file published on the webserver ?

The Test-URI function can be accessed from:

$WebClient = New-Object System.Net.WebClient

$MaxFileLimit = 1200

For ($i=1; $i -le $MaxFileLimit; $i++) {
  $url = (-join("$i"));
  test-uri $url -detail -ErrorAction SilentlyContinue;
  $WebClient.DownloadFile($url, $target);

Open in new window

Any help would be greatly appreciated.

Senior IT System EngineerIT ProfessionalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
save the function as a module
i.e. in your documents\windowspowershell folder, change to the modules folder and save the function script as a psm1 file i.e. test-url.psm1 in a subfolder called test-url i.e. G:\Documents\WindowsPowerShell\modules\test-uri>

you can then import-module test-uri
import-module test-uri -ErrorAction Stop
$WebClient = New-Object System.Net.WebClient

$MaxFileLimit = 1200

For ($i=1; $i -le $MaxFileLimit; $i++) {
  $url = (-join("$i"))
  if ((test-uri $url -detail -ErrorAction SilentlyContinue) -eq $true)
    $WebClient.DownloadFile($url, $target)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Senior IT System EngineerIT ProfessionalAuthor Commented:
Hi David, thanks for the assistance in this matter.

When I put the script you've suggested and the Test-URI into the single page on the Windows PowerShell ISE I ran as Administrator, there is nothing reported on the screen, nor anything downloaded into the C:\UAT\Files directory?

When I copy pasted the multiple URL manually below to the new browser on the different PC:

I can download the files manually one by one.
Jason CrawfordTransport NinjaCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: David Johnson CD MVP (https:#a42449052)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.