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: https://www.petri.com/testing-uris-urls-powershell

$target="C:\UAT\Files";
$WebClient = New-Object System.Net.WebClient

$MaxFileLimit = 1200

For ($i=1; $i -le $MaxFileLimit; $i++) {
  $url = (-join("http://Submission.MyCompany.com/view.php?mod=url&id=$i"));
  test-uri $url -detail -ErrorAction SilentlyContinue;
  $WebClient.DownloadFile($url, $target);
}

Open in new window


Any help would be greatly appreciated.

Thanks,
LVL 9
Senior IT System EngineerIT ProfessionalAsked:
Who is Participating?
 
David Johnson, CD, MVPConnect With a Mentor OwnerCommented:
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
$target="C:\UAT\Files";
$WebClient = New-Object System.Net.WebClient

$MaxFileLimit = 1200

For ($i=1; $i -le $MaxFileLimit; $i++) {
  $url = (-join("http://Submission.MyCompany.com/view.php?mod=url&id=$i"))
  
  if ((test-uri $url -detail -ErrorAction SilentlyContinue) -eq $true)
    {
    $WebClient.DownloadFile($url, $target)
  }
}

Open in new window

1
 
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:
http://Submission.MyCompany.com/view.php?mod=url&id=1000
http://Submission.MyCompany.com/view.php?mod=url&id=1001
http://Submission.MyCompany.com/view.php?mod=url&id=1010
...
http://Submission.MyCompany.com/view.php?mod=url&id=2001

I can download the files manually one by one.
0
 
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.

exchangepro
Experts-Exchange Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.