Powershell 更新

Powershell 更新

我的 powershell 版本是:

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

我有以下命令可以更新到最新版本:
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

我可以使用上述命令来更新我的 Powershel 吗?或者还有其他方法可以做到这一点?

如果我更新 powershel,我已有的脚本还能正常工作吗?

答案1

PowerShell 5.x 是操作系统安装的一部分。

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"将把当前的 PowerShell Core 7.x 安装为单独的产品,它不完全兼容。

答案2

正如其他评论和答案所说,您不能用 替换PS 5.1PS Core但您可以同时安装它们。PS Core是 MS 希望您使用的版本,也是经常更新的当前版本。

如果你想安装/更新你的 PS Core 版本,另一种方法是使用温格特

在 Windows 11 和 Windows 10 的某些版本中,它已默认安装,否则你可以下载它这里

搜索包:

winget search powershell

安装软件包:

winget install PowerShell

它的美妙之处在于,当有可用的升级时,您只需执行以下操作:

winget upgrade PowerShell

这是我刚刚完成的升级的示例输出:

PS C:\Users> winget upgrade powershell
Found PowerShell [Microsoft.PowerShell] version 7.2.4.0
This application is licensed to you by its owner.
Microsoft is not responsible for and does not license third-party packages.
Downloading https://github.com/PowerShell/PowerShell/releases/download/v7.2.4/PowerShell-7.2.4-win-x64.msi
  ██████████████████████████████ 101 MB / 101 MB
The installer hash was successfully verified
Package installation is started...

PS C:\Users>

相关内容