Home > Back-end >  How to use regex with Invoke-WebRequest
How to use regex with Invoke-WebRequest

Time:12-29

I want to fetch the latest 64 bit Git for Windows using the Invoke-WebRequest command and here's the Regex for it https://github.com/git-for-windows/git/releases/latest/download/Git-([0-9] (\.[0-9] ) )-64-bit\.exe

(The 64 bit binaries are named like Git-[numbershere]-64-bit.exe, for example Git-2.34.1-64-bit.exe)

Now, I don't know how to pair this with Invoke-WebRequest to make it work. Can someone help?

CodePudding user response:

As Jeroen Mostert points out: you don't

Instead, you could use GitHub's public API to fetch metadata about the latest release, then pick the appropriate url from there:

# fetch metadata for latest release
$latestRelease = Invoke-RestMethod "https://api.github.com/repos/git-for-windows/git/releases/latest" 

# enumerate included assets, find the appropriate one
$exe64bit = $latestRelease.assets |Where-Object name -like 'Git-*-64-bit.exe'

# output the appropriate browser URL
$exe64bit.browser_download_url
  • Related