我最近在全新的 Windows 10 电脑 (19042) 上安装了 PoweShell 7.1.1。现在当我启动它时,它显示有新的稳定版本可用 7.1.2,请立即升级或查看发布页面。
问题
是否有内置的自我升级命令,或者我只需转到发布页面,下载最新版本并运行安装程序?(后一种情况会正确吗?升级,还是只是覆盖,或者其他什么,导致副作用?)
答案1
6 个选项。
# 1 - Install PowerShell Core
Invoke-Expression -Command "& { $(Invoke-RestMethod -Uri 'https://aka.ms/install-powershell.ps1') } -UseMSI"
# https://enterinit.com/cs/powershell-7-preview-install-and-upgrade
# Save the above script and run as needed.
# 2 - Via a module
Install-Module -name PSReleaseTools -Force
Install-PSPreview -mode Quiet
# https://adamtheautomator.com/updating-to-powershell-7
# 3 - Install-Powershell
install-powershell.ps1 -Daily
# https://github.com/PowerShell/PowerShell/blob/master/tools/install-powershell.ps1
# 4 - From a cmdlet
Invoke-RestMethod -Uri 'https://aka.ms/install-powershell.ps1' |
New-Item -Path function: -Name Install-PowerShell |
Out-Null
<#
It creates a new cmdlet Install-PowerShell with a number of useful parameters.
For example, to download the latest production version of PowerShell 7 as a
portable app in a folder of your choice, run this:
#>
Install-PowerShell -Destination 'c:\ps7test' -AddToPath
<#
If you prefer to install PowerShell 7 as a managed MSI application, run this
instead:.
#>
Install-PowerShell -UseMSI -Quiet
# Note: A truly quiet installation requires Administrator privileges.
# 5 - Chocolaty
choco install powershell-core -y
# https://chocolatey.org/packages/powershell-core
# 6 - Linux
wget -O - https://aka.ms/install-powershell.sh | sudo bash
# https://www.thomasmaurer.ch/2019/03/how-to-install-and-update-powershell-6
答案2
目前,在 Windows 10/11 上升级 PowerShell 的最简单方法是使用内置的 winget 工具。
winget upgrade --id Microsoft.PowerShell --exact --silent --scope machine