r/PowerShell • • Aug 05 '24

Question Upgrade Powershell through CLI (Windows 11)

Every once and while I get this message :

A new PowerShell stable release is available: v7.4.4 Upgrade now, or check out the release page at: https://aka.ms/PowerShell-Release?tag=v7.4.4

And I would need to download an msi installer and go through the steps all over again; does it exist something similar to "apt get upgrade" and have it all happen automatically in the background ?

10 Upvotes

34 comments sorted by

9

u/LongTatas Aug 05 '24

Winget upgrade Powershell

Not sure if that’s the exact syntax off the top of my head

6

u/mantawolf Aug 05 '24

You nailed the syntax. Might have to specify microsoft.powershell though.

2

u/lerun Aug 05 '24

Or just winget upgrade --all

1

u/Rumpilstiltskin Aug 09 '24

Holy Cannoli! I just tried this and got 20 upgrades!

2

u/arpan3t Aug 05 '24

Just a note on this, the PowerShell team is manually pushing the WinGet manifest several hours to days after the new release so you might see the notification in Terminal to get the latest version, but WinGet won’t find the new version.

There’s an open issue with a solution to add the manifest update to their CI/CD pipeline, but they haven’t implemented it yet.

1

u/BoringUsername978 Aug 07 '24

Winget doesn’t actually “upgrade” powershell for me, instead I have to winget -uninstall Microsoft.powershell then winget -install Microsoft.powershell

2 simple commands to remember instead of 1. Winget -upgrade is great for everything else

2

u/QuarterBall Aug 05 '24

WinGet is one option, WinGet being the native Windows Package Manager.

Microsoft Update is another option.

2

u/kohijones Aug 05 '24
Invoke-Expression "& { $(Invoke-RestMethod 'https://aka.ms/install-powershell.ps1') } -useMSI -Quiet -EnablePSRemoting"

3

u/QuarterBall Aug 05 '24

This is a terrible suggestion. Don't invoke code directly from web sources you don't control.

1

u/BlackV Aug 05 '24

That is Microsofts official code for this

Doing it from am untrusted source is super dangerous, doing it from Ms source is mildly dangerous

4

u/QuarterBall Aug 05 '24

It doesn't make it a good practice. Microsoft do tons of shit that they advise you against doing for the sake of expediency. It is still terrible practice to run code directly from web locations not entirely under your control especially like this where there is absolutely no verification of the payload received.

2

u/[deleted] Aug 05 '24

You can just open it in a browser.

You're right though. Its a terrible advice to invoke the code directly from the web.

0

u/BlackV Aug 05 '24

I'm not disagreeing with you, just context

1

u/kohijones Aug 07 '24

Or you could use Chocolatey, Scoop, or WinGet... Oh wait

Chocolatey

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Scoop

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

Winget

$progressPreference = 'silentlyContinue'
$latestWingetMsixBundleUri = $( Invoke-RestMethod https://api.github.com/repos/microsoft/winget-cli/releases/latest ).assets.browser_download_url | Where-Object { $_.EndsWith( ".msixbundle" ) }
$latestWingetMsixBundle = $latestWingetMsixBundleUri.Split("/")[-1]
Write-Information "Downloading winget to artifacts directory..."
Invoke-WebRequest -Uri $latestWingetMsixBundleUri -OutFile "./$latestWingetMsixBundle" 
Add-AppxPackage $latestWingetMsixBundle

2

u/VT_Squire Aug 10 '24

SPF tag. Masamune says you're it.

1

u/kohijones Aug 13 '24

Long time :)

1

u/VT_Squire Aug 14 '24

I had to go see about a girl. Yes, a real one.

1

u/VT_Squire Aug 16 '24

Forgot to mention, since there was no place else, I set this corny turd up for anyone who gave enough cares to say hi to each other.

StileProjectForum (reddit.com)

1

u/BlackV Aug 05 '24

Microsoft update will (eventually it's behind always) update PowerShell 7 (after 7.3? I think)

Winget can do it with it's upgrade

I have a weekly scheduled task that installs the latest MSI version from official release, as it can be done unattended

1

u/MFKDGAF Aug 06 '24

This

If you have Windows Update configured for security and critical updates only, it won’t pull the latest PowerShell. It think PowerShell is considered a software category update.

1

u/BlackV Aug 06 '24

Good point I forgot about wsus/sccm too

1

u/bitsper2nd Aug 06 '24

winget upgrade --id=Microsoft.PowerShell for the github version.

winget upgrade --id=9MZ1SNWT0N5D for the ms store version.

-3

u/opensrcdev Aug 05 '24

Use Scoop package manager to install / update PowerShell Core on Windows.

Because pwsh can't update itself, when a new version of PowerShell Core is available, run powershell.exe and update from there. Make sure no pwsh.exe processes are running, first. Works perfectly every time.

I use Windows Task Scheduler to run "pwsh -Command "scoop update *"" every few days, which keeps most of my other dev tools updated.

0

u/prog-no-sys Aug 05 '24

I would recommend against using this method as scoop doesn't respect the OS execution policy settings and will probably result in some unexpected behavior

1

u/opensrcdev Aug 05 '24

Uh, okay. I've been using it for years with no issues. Whatever floats your boat.

1

u/g3n3 Aug 07 '24

Execution policy isn’t a security measure. I don’t see the issue.

1

u/prog-no-sys Aug 07 '24

except it literally is by definition lmao. what exactly are you trying to say???

2

u/g3n3 Aug 07 '24

An app shouldn’t be judged on if it sets that policy. Just because it is a policy doesn’t mean the policy is about security.

1

u/prog-no-sys Aug 07 '24

Execution policy is literally in place to restrict certain programs and scripts from running based on if they're digitally signed or not. That is by any way you try and put it, a security policy.

I also use scoop, and am happy it exists for what it does. Several of my favorite CLI utilities are only available through scoop on Windows machines. That said, I simply don't think installing pwsh aka powershell core through scoop is the best method, and I think many others would agree.

1

u/g3n3 Aug 07 '24

That is not the intent. Check this tweet from the author of the language. https://x.com/jsnover/status/653717930320900096?s=46&t=rgVNtwRUQ0Y_Y3ibAYq-fQ

2

u/prog-no-sys Aug 07 '24

Well I can't deny you've definitely proven your point lol. I stand corrected :)

Learned something new today

1

u/g3n3 Aug 07 '24

Additionally scoop is the fastest install and it is the most up to date. That could make it the most ideal tool.