How to upgrade PowerShell version
Asked Answered
T

3

7

Lately, firing up PowerShell, I noticed that there is a phrase that says:

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

So why not trying it following the actual Microsoft documentation:

  1. I run $PSVersionTable and the version installed is 5.1
  2. I run winget search Microsoft.PowerShell and it says that version 7.2 is available as well as the 7.3 preview version
  3. I run winget install --id Microsoft.Powershell --source winget and version 7.2 is installed
  4. I run $PSVersionTable again and I'm still on 5.1

enter image description here

Let's try to install it through dotnet:

  1. I run dotnet tool install --global PowerShell and the terminal says Tool 'powershell' (version '7.2.6') was successfully installed.
  2. I run $PSVersionTable and I'm still on 5.1

enter image description here

I'm following the current Microsoft documentation, where am I wrong?

Totality answered 3/10, 2022 at 19:22 Comment(0)
R
8

Powershell 7 (core) is its own application. Search for pwsh.exe and run that

Retouch answered 3/10, 2022 at 19:31 Comment(4)
That is true, pwsh.exe made the trick. But why I cannot set PowerShell 7 as the default PowerShell?Totality
@FrancescoMantovani PS 7 isn't fully compatible with PS 5.1, so it's best to keep both installed in parallel. And why bother, when pwsh is even shorter to type than powershell.Romona
Good point, I was just curious. Thank youTotality
@FrancescoMantovani In case you are wondering what the changes from PS 5.1 to PS 7.x are, here is a good overview: learn.microsoft.com/en-us/powershell/scripting/whats-new/…Romona
K
5

To upgrade Poweshell version 7:

winget upgrade --id Microsoft.PowerShell

Sources:

Kielce answered 21/6 at 18:45 Comment(2)
The question says that Francesco did run that command before he asked the question, albeit with an extra --source parameter.Nanceenancey
What if you don't have winget?Rorke
D
1

You don't need to upgrade it, as the other answer suggests (they should cohabit), but you can default to the newer one in windows terminal.

This blog showed me how, it's very simple:

https://www.codyhosterman.com/2020/05/defaulting-windows-terminal-to-powershell-7-x-core/

  1. open settings and click 'open json file' at the bottom.
  2. replace the default guid with the one from the ps7 section.
  3. save and restart terminal

Thanks, cody!

Delinda answered 28/3, 2023 at 15:6 Comment(1)
This was useful. Thx 3yrs+ later, seems its now easier by just going to Settings > selecting the "Default profile" on the GUIRoband

© 2022 - 2024 — McMap. All rights reserved.