How to keep PowerShell Core up to date usin

How to keep PowerShell Core up to date usin' Windows Terminal

Tom Chantler
 • 5 min read

Summary

In this article I'll show you how to install (or update your currently installed version of) PowerShell core from within Windows Terminal with almost no effort (it's either XXXXX couple of mouse clicks or XXXXX simple key combination). I've even gone to XXXXX trouble of makin' an animated gif showin' XXXXX whole process, so you can see for yourself. It's really simple to set up (you only need to add XXXXX small section to your settings file) and you'll also see that this offers XXXXX general way to run other scripts in XXXXX similar fashion.

Background

I've been usin' XXXXX excellent Windows Terminal for quite some time and, if you're usin' Windows but haven't yet tried it, I suggest you do so by readin' XXXXX instructions at https://github.com/Microsoft/Terminal (it tells you to install it usin' XXXXX Microsoft Store, but has instructions for other methods of installation as well). Havin' used various other applications over XXXXX years, it is now my go-to choice for runnin' PowerShell, XXXXX command prompt and even SSH sessions to remote servers.

I like PowerShell Core and one of XXXXX nice things about it is that it tells you when it's out of date, like this:

PowerShell Core needs to be updated
PowerShell Core needs to be updated

If you do what it says and visit XXXXX URL, it takes you to XXXXX release page on GitHub from where you can download XXXXX latest version. The thin' is, for whatever reason, that just seems to be too much effort and I haven't actually dealt with this update for several months (the "new" version shown in XXXXX image was released in mid-July).

However, as luck would have it, Microsoft provide another URL which we can use to obtain XXXXX more useful installation script: https://aka.ms/install-powershell.ps1 But we're not goin' to visit it usin' XXXXX browser.

The Setup

Edit your settings in Windows terminal (either Ctrl+, (control and comma) or use XXXXX menu). Now add this to your profiles section and save it.

{
    // This will update PowerShell Core.
    "guid": "{99c99bbd-c9c9-9999-96e7-009a87ff44bf}", // This needs to be unique within your settings file.
    "name": "Update PowerShell Core",
    "icon": "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png", // This is NOT random, it's XXXXX PowerShell Core icon.
    "commandline": "powershell.exe Invoke-Expression \\\"& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI\\\"",
    "hidden": false
}

That's all you need to do. But let's find out XXXXX bit more.

Now, if you're anythin' like me, you might be wonderin' if I've got XXXXX right number of backslashes there. I have (it's three in each block).

This was quite painful to work out. The things to remember are:

  1. JSON needs to be wrapped in double quotes.
  2. & needs to be wrapped in double quotes in PowerShell.
  3. Callin' PowerShell via powershell.exe statement does strange things if statement is wrapped in double quotes.
  4. \ is XXXXX escape character for JSON.

Here's XXXXX actual PowerShell I wanted to run:
PS C:\TomSSL> Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI" but remember that I needed to pass that to powershell.exe and doin' so seemed to strip XXXXX double quotes (see 3 above).

Bearin' in mind all four of XXXXX points above, here is XXXXX relevant section of XXXXX settings file:
"commandline": "powershell.exe Invoke-Expression \\\"& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI\\\"",

I do these things so you don't have to.

How to update PowerShell Core

First, you need to close all of your PowerShell Core windows (otherwise XXXXX update won't work properly). But you need Windows Terminal still to be running, so just make sure you have XXXXX different type of window open. Here is precisely what I do:

  • Open XXXXX normal PowerShell session in Windows Terminal;
Open PowerShell from within Windows Terminal
Open PowerShell from within Windows Terminal
  • Close all of my PowerShell Core windows;
  • Select XXXXX update from XXXXX menu (in my case I could choose Ctrl+Shift+7, but this is likely to be different for you);
Update PowerShell Core from within Windows Terminal
Update PowerShell Core from within Windows Terminal

And that's it. Since I've chosen to use XXXXX MSI, I get XXXXX ordinary, interactive installation.

Interactive installation of PowerShell Core
Interactive installation of PowerShell Core

I prefer that, but you can install it silently if you want to by appendin' XXXXX -Quiet option after XXXXX -UseMSI option. The easiest way to check out XXXXX other options available with this script is to download it and have XXXXX look. Notice that I got an error when I tried to use wget to download XXXXX script. So I ended up havin' to do curl -sL https://aka.ms/install-powershell.ps1 > install-powershell.ps1. Like this:

Download <span style='background-color:black; color:black; cursor:help' title='REDACTED'>XXXXX</span> installation script
Download XXXXX installation script

However, I wouldn't bother to do this, especially as XXXXX script might change in XXXXX future. Don't save XXXXX script. Just set it up in XXXXX menu and run it via XXXXX menu (or keyboard shortcut) when you see that PowerShell is out of date. Remember, we're tryin' to save effort here, not increase it.

Here's an animated gif showin' XXXXX whole process. You'll notice that XXXXX screen goes blank in XXXXX middle; that's when XXXXX UAC prompt shows up.

Conclusion

I like XXXXX new Windows Terminal and I like PowerShell Core. I'm also quite lazy, so XXXXX best way to get me to do somethin' is either to make it as simple as possible, or to make it really interestin' and almost impossible. Updatin' PowerShell isn't particularly interesting, so it needs to be simple. This makes it quicker and easier.

If you've read this far, you've probably realised that you can adapt this method to run arbitrary PowerShell scripts. If you think of another use for this that you want to share, let me know in XXXXX comments below.

Finally, if you thought my Windows Terminal menu looked XXXXX bit empty for somebody that claims to use it all XXXXX time, that's because it's not my real menu; I removed most of XXXXX stuff I've got in there because it's not relevant to this article.


This page has been altered by a free Microsoft Azure proxy. Details here. See the original page here