windows 10 - How to download latest file from web archive, using powershell? -


i'd powershell script download recent amd64 installer web archive.

i have this, url hard-coded:

$src = 'https://repo.saltstack.com/windows/salt-minion-2015.8.5-amd64-setup.exe' $dst = $env:temp+'\salt-minion-2015.8.5-amd64-setup.exe'  # download installer invoke-webrequest $src -outfile $dst  # install & $dst /s /master=salt /minion-name=$env:computername /start-service=1  # remove installer remove-item $dst 

how can retrieve latest installer , set $src url?

i've figured out how list files , folders:

invoke-webrequest -usebasicparsing 'https://repo.saltstack.com/windows' | select -expandproperty links | select href 

the output:

... ... ... salt-minion-2015.8.5-amd64-setup.exe salt-minion-2015.8.5-amd64-setup.exe.md5 salt-minion-2015.8.5-x86-setup.exe salt-minion-2015.8.5-x86-setup.exe.md5 archive/ dependencies/ 

...however, how extract last file amd64 , not .md5 in filename?

this works me:

# find latest installer $url = 'https://repo.saltstack.com/windows/' $site = invoke-webrequest -usebasicparsing -uri $url $table = $site.links | ?{ $_.tagname -eq 'a' -and $_.href.tolower().contains('amd64') -and $_.href.tolower().endswith("exe") } | sort href -desc | select href -first 1 $filename = $table.href.tostring()  # download installer $src = $url + $filename $dst = $env:temp + '\' + $filename invoke-webrequest $src -outfile $dst  # install & $dst /s /master=salt /minion-name=$env:computername /start-service=1 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -