I am trying to automate updating KeePass in a few computers using powershell, so I'm interested in some sort of way to automatically download the latest release from sourceforge, however I cannot make it work. I've seen a lot of references by googling but none work for me. I'm trying this at the current time:
$url=https://sourceforge.net/projects/keepass/files/latest/download
#$url=https://sourceforge.net/projects/keepass/files/KeePass%202.x/2.49/KeePass-2.49-Setup.exe
Invoke-WebRequest -Uri $url -OutFile $env:USERPROFILE'\Downloads\KeePass2-Latest.exe'
Both of these download the web's page file, not the installer itself.
According to this Sourceforge post "The regular download link will work, as long as the download function is able to follow redirects, and does not appear to be a browser source (eg., doesn't have a browser-like User-Agent String), it will simply redirect to the file itself."
However it's not working for me, I'm not specifying any UserAgent, and I've even tried to use -UserAgent $null as a parameter, but no luck.
Is there a way to programatically download from sourceforge using command-line/Powershell?
According to the documentation, the default user agent of
Invoke-WebRequestis similar to:This might be interpreted as a browser user agent by SourceForge and therefore might not be a good candidate to be redirected immediately.
The documentation of SourceForge states, that they offer a direct download, when using
wgetfor example:The default user agent of
wgetlooks like the following, where the number represents the current version ofwget:Wget/1.21.1Wget/1.21.1 (linux-gnu)Using just
Wgetas the user agent will already be enough to donwload the executable directly:As KeePass only offers a Windows executable anyway, you don't have to worry about Linux or macOS binaries/packages.