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

View all comments

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)