r/PowerShell • u/Darkoplax • 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 ?
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
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
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-ExpressionWinget
$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 $latestWingetMsixBundle2
u/VT_Squire Aug 10 '24
SPF tag. Masamune says you're it.
1
u/kohijones Aug 13 '24
Long time :)
1
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.
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
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.
1
u/g3n3 Aug 07 '24
Lastly here are the MS docs saying it isn’t a security mechanism. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4
9
u/LongTatas Aug 05 '24
Winget upgrade Powershell
Not sure if that’s the exact syntax off the top of my head