Created
March 4, 2020 22:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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