Skip to content

Instantly share code, notes, and snippets.

@quonic
Created March 4, 2020 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quonic/3670b26878ad628a73960c94322ace84 to your computer and use it in GitHub Desktop.
Save quonic/3670b26878ad628a73960c94322ace84 to your computer and use it in GitHub Desktop.
Checks if the current running Powershell Core environment is the latest version and download if it isn't
[Version]$ReleaseVersion = (Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json).ReleaseTag -replace '^v'
if ($PSVersionTable.PSEdition -like "Core" -and $ReleaseVersion -gt $PSVersionTable.PSVersion) {
$latest = Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/PowerShell/releases" | Where-Object { $_.tag_name -eq "v$ReleaseVersion" }
$downloadUrl = $latest.assets | Where-Object Name -like "*win-x64.msi" | Select-Object -ExpandProperty 'browser_download_url'
Invoke-WebRequest -Uri $downloadUrl -OutFile "$PSScriptRoot\$(Split-Path $downloadUrl -Leaf)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment