Trying to download a zip file from a weblink with powershell

后端 未结 1 1955
时光取名叫无心
时光取名叫无心 2021-01-23 01:10

Ok, I am trying to download a file off of a web link that we use with powershell. I am downloading a zip file where the begining of the name is always the same, but the the mid

1条回答
  •  终归单人心
    2021-01-23 01:44

    If the site has directory browsing enabled (unlikely unless you have control of the site and can turn it on), you can do this:

    $url = 'http://blah/blah/blah/'
    $wr = iwr $url
    $filename = $wr.Links.href | Where {$_ -match 'My File Name.*?\.zip'}
    $wr = iwr "$url/$filename"
    

    If the site doesn't have directory browsing enabled then surely it has a page with a link to the ZIP file on it. Download that page and use the same $wr.Links.href trick to get all the links and look for the one that matches "My File Name.*?.zip".

    0 讨论(0)
提交回复
热议问题