如何安装和更新PowerShell 7

Windows PowerShell默认情况下安装在Windows系统上。但这是Windows Powershell,而不是PowerShell。为了充分利用PowerShell,您应该升级到PowerShell 7。在本文中,您将学习如何安装和更新PowerShell 7。

Windows Powershell vs PowerShell

您需要注意两个PowerShell版本:

  • Windows PowerShell(版本1.0 - 5.1)
    它已预装在所有现代Windows客户端和服务器OS版本上。它没有进一步开发,最新版本为5.1。可执行文件是powershell.exe。
  • Powershell(第6版及更高版本)
    它尚未预装在任何版本的Windows上。它正在积极开发,更快,并且具有更好的命令。可执行文件是pwsh.exe。

笔记:您可以在同一系统上同时安装Windows PowerShell和PowerShell版本。

自从首次发行以来,Powershell已经走了很长一段路。有关所有PowerShell版本及其发布日期,请参见下表。

PowerShell版本发布日期支持结束
Powershell 7.52025年1月23日2026年5月12日
Powershell 7.42023年11月16日2026年11月10日
Powershell 7.32022年11月9日2024年5月8日
Powershell 7.22021年11月8日2024年11月8日
Powershell 7.12020年11月11日2022年5月8日
Powershell 72020年3月4日2022年12月3日
Powershell 6.22019年3月29日2020年9月4日
Powershell 6.12018年9月13日2019年9月28日
Powershell 6.02018年1月20日2019年2月13日
Windows Powershell 5.12016年8月2027年1月
Windows PowerShell 5.02015年2月2016年8月
Windows PowerShell 4.02013年10月2023年10月
Windows Powershell 3.02012年10月2023年10月
Windows PowerShell 2.02009年7月2020年1月
Windows PowerShell 1.02006年11月2020年1月

查找PowerShell版本

要检查您正在运行的PowerShell版本,请启动Windows PowerShell或PowerShell作为管理员,并在下面运行命令。

笔记:Windows PowerShell和PowerShell是不同的版本,您需要启动正确的PowerShell窗口并在下面运行命令。

$PSVersionTable.PSVersion

如果您运行它,这就是看起来的样子Windows PowerShell

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      20348  1

请参阅下面的屏幕截图。

如果您运行它,这就是看起来的样子Powershell

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      4      0

请参阅下面的屏幕截图。

安装PowerShell 7

有不同的方法可以在系统上安装PowerShell。遵循以下方法之一。

方法1:单线

这是安装PowerShell 7的最快,最简单的方法。

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

之后,您可以看到可以通过的PowerShell 7设置向导。

另请阅读:如何使用PowerShell安装Windows更新

确保您启用所有选项。

由于PowerShell 7.2及更高版本,如果您在设置向导中启用了Microsoft在同一发行频道中自动更新PowerShell 7。例如,PowerShell 7.2.x至7.2.y和7.3.x至7.3.y。

启用这两个选项。

完成安装。

PowerShell 7出现在您的程序中。

方法2。从github下载

PowerShell GitHub发行页面并下载PowerShell 7安装程序。

打开powerShell .msi文件并通过上述方法所示的设置向导。

方法3:Winget(Windows软件包管理器)

运行下面的命令以下载并安装PowerShell 7。

笔记:下载后,它将自动安装PowerShell 7,您将看不到设置向导。

winget install --id Microsoft.Powershell

更新PowerShell 7

始终使用最新的PowerShell 7版本保持最新状态。这是因为新功能,错误修复以及最重要的是,对安全漏洞进行了修补。

使用winget升级命令将PowerShell 7更新为最新版本。

winget upgrade --id Microsoft.PowerShell

另一种方法是使用下面的单线。

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -Quiet -UseMSI"

升级PowerShell 7的另一种方法是从Girub,然后您可以通过设置向导更新PowerShell。

常见问题(常见问题解答)

安装PowerShell 7后,如何在Windows上卸载Windows PowerShell 5.1?

你没有。它与Windows OS集成在一起,您必须将其放在系统上。

当我安装PowerShell 7时,为什么Windows Powershell ISE显示5.1版?

PowerShell ISE加载Windows PowerShell 5.1而不是PowerShell 7。

如何与PowerShell 7一起使用Windows Powershell ISE?

切换到Visual Studio代码。这是一个免费的,轻巧的开源,跨平台代码编辑器。

PowerShell 7会在Visual Studio代码中自动加载吗?

PowerShell 7优先于Windows PowerShell 5.1,默认情况下负载。

我可以在Visual Studio代码中的Windows Powershell 5.1和PowerShell 7之间切换吗?

选择默认配置文件,然后选择Windows PowerShell 5.1或PowerShell 7。

我们怎么知道PowerShell 7中支持哪些CMDLET和模块?

微软保留一个模块和CMDLET的释放历史记录

为什么Microsoft不带Windows Ship PowerShell 7?

Microsoft计划最终将Windows Powershell 7运送为Windows PowerShell 5.1的并排功能。但是他们仍然需要解决一些细节,并且没有时间表何时发生。

我应该使用Windows PowerShell 5.1还是PowerShell 7?

您绝对应该在可能的情况下使用PowerShell 7。但是,在过渡到PowerShell 7之前,请确保您测试所有CMDLET和脚本。

结论

您学习了如何安装和更新PowerShell 7。确保在可能的情况下使用PowerShell 7,因为Microsoft保持最新状态,并且执行速度比较旧版本更快。如果不可能将某些命令和脚本移植到PowerShell 7中,请继续使用PowerShell 5.1。

你喜欢这篇文章吗?您可能还喜欢如何清除Microsoft团队缓存。不要忘记关注我们并分享这篇文章。