mercredi 20 avril 2016

How to set file name to default when downloaded with PowerShell

Just started using powershell on windows 7 and I want to download a file from a site that doesn't include the name of the file in the url. Right now I am using

$webclient = New-Object System.Net.WebClient
$src = "http://just-some-short-url/"
$dest = "C:\Users\Downloads\some-file-2.53.jar"
$webclient.DownloadFile($src,$dst)

And this works but only because I specify the name with some hard-coded value. But I really just want to say

$webclient = New-Object System.Net.WebClient
$src = "http://just-some-short-url/"
$dest = "C:\Users\Downloads\"
$webclient.DownloadFile($src,$dst)

So that whatever version is downloaded would just be named such in the C:\Users\Downloads\ so for example next month when there is a new update to the file I get from the same link presumably I would then have a file named some-file-2.54.jar However the latter code throws an error and is only fixed by hard coding the file name.




Aucun commentaire:

Enregistrer un commentaire