Is your PowerShell Core up to date?

I have been using PowerShell Core for a while now, its great not to have to spin up a windows VM every time I want to work with PowerShell on Mac!

Let’s face it though, not everything is there at the moment, so every time there is an update I want to know.  The Microsoft team are doing a great job of updating PowerShell Core and it seems like every time I go check there is a new version which fixes bug or introduces new cmdlets.

This does however mean I need to constantly go check the releases page or keep an eye on twitter to see when new releases come out.. until now!

The following function is a 5 minute function I wrote to keep on top of the updates, I have placed it in my PowerShell profile and now every time I launch PowerShell from my mac it checks and tells me if there is a new version as below:

Code

Just use the following code and paste it into the file located at $profile and every time you launch PowerShell it will go check for you!

Function Get-PowerShellRelease {
    #Using this to get rid of the nasty output Invoke-WebRequest gives you in PowerShell on the Mac
    $progress = $ProgressPreference
    $ProgressPreference = "SilentlyContinue"
    $JSON = Invoke-WebRequest "https://api.github.com/repos/powershell/powershell/releases/latest"| ConvertFrom-Json
    If ($psversiontable.GitCommitId) {
        If ($JSON.tag_name -ne $psversiontable.GitCommitId) {
            Write-Output "New version of PowerShell available!"
            $JSON.body
        } Else {
            "PowerShell is currently up to date!"
        }
    }
    $ProgressPreference = $progress
}

Get-PowerShellRelease

5 thoughts on “Is your PowerShell Core up to date?”

  1. There really is no need to save and restore preference variable state within your function. The state you change it to is only local to the function anyway, so it doesn’t have any effect on the variable at the parent scope either way.

Leave a Reply