Often, URLs redirect to the final URL, so if you’d like to know where a given URL really points to, use a function like this:

function Resolve-Url
  $request = [System.Net.WebRequest]::Create($url)
  $response = $request.GetResponse()
  $url = $response.GetResponseHeader("Location")
  return $url

For example, the latest PowerShell release is always available via this url: https://github.com/PowerShell/PowerShell/releases/latest

By resolving this URL, you get back the currently active latest URL which in turn is a quick way of finding the latest PowerShell version available:

PS C:\> Resolve-Url -url https://github.com/PowerShell/PowerShell/releases/latest

PS C:\> ((Resolve-Url -url https://github.com/PowerShell/PowerShell/releases/latest) -split '/')[-1]

PS C:\> [version](((Resolve-Url -url https://github.com/PowerShell/PowerShell/releases/latest) -split '/')[-1] -replace 'v')

Major  Minor  Build  Revision
-----  -----  -----  --------
6      2      1      -1  

Twitter This Tip! ReTweet this Tip!