0

I have a script that nearly works but I need to add in either parsing or a wildcard on the URL as the URL will change to characters I won’t know each month. I have to use New-Object System.Net.WebClient because invoke web request is blocked. So, I was thinking if anyone knows how to download the link using the characters that I will know and strip off the rest of the link.

Examples of the links below

Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip
Full-CSV-data-file-Dec18-ZIP-3427K.zip
Full-CSV-data-file-Nov18-ZIP-3543K-21860.zip

So on the above links i know the latest file will have Jan19 in it and it's a zip file. The script i am using is

$currentMonthNo = get-date -format "MM"
$currentMonthName = (get-date((get-date).addmonths(-2)) -format MMM)
$currentYearNo = get-date –format yy
$url = "http://www.website.com/Full-CSV-data-file-$currentMonthName$currentYearNo-ZIP-3633K-53821.zip"
$output = "C:\Folder\Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
#OR
(New-Object System.Net.WebClient).DownloadFile($url, $output)

Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
Write-Output $url
Start-Sleep -s 6
7
  • I am unsure what you are asking here. Are we trying to rename the zip file after you download it? Commented Mar 15, 2019 at 13:43
  • I'm trying to automate downloading the file Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip but next month it could be Full-CSV-data-file-Feb19-ZIP-44466K-77766.zip i will only know the month has incremented 1 month and the year is current year and that it's a zip file the rest of the link i won't know how it looks Commented Mar 15, 2019 at 13:53
  • 1
    You can't wildcard URL's. You need to check something else first that gets you the names. Scrape the page before for example Commented Mar 15, 2019 at 13:55
  • Hence the question, how would i parse links or regex for zip file using System.Net.WebClient Commented Mar 15, 2019 at 14:00
  • 1
    Start here then: stackoverflow.com/questions/49418802/… Commented Mar 15, 2019 at 14:30

0

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.