当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何安装和更新 PowerShell 7

作者:精品下载站 日期:2024-12-14 06:31:31 浏览:15 分类:玩电脑

如何安装和更新 PowerShell 7


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

Windows PowerShell 与 PowerShell

您需要注意两个 PowerShell 版本:

  • Windows PowerShell(版本 1.0 - 5.1)
    它预装在所有现代 Windows 客户端和服务器操作系统版本上。它没有进一步开发,最新版本是5.1。可执行文件是powershell.exe

  • PowerShell(版本 6 及更高版本)
    它未预安装在任何版本的 Windows 上。它正在积极开发中,速度更快,并且具有更好的可用命令。可执行文件是pwsh.exe

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

PowerShell 版本和发布日期

自首次发布以来,PowerShell 已经取得了长足的进步。请参阅下表了解所有 PowerShell 版本及其发布日期。

PowerShell 7.4

2023 年 11 月

PowerShell 7.3

2022 年 11 月

PowerShell 7.2

2021 年 11 月

PowerShell 7.1

2020年11月

PowerShell 7

2020年3月

PowerShell 6.2

2019年3月

PowerShell 6.1

2018年9月

PowerShell 6.0

2018年1月

Windows PowerShell 5.1

2016年8月

Windows PowerShell 5.0

2015年2月

Windows PowerShell 4.0

2013年10月

Windows PowerShell 3.0

2012年10月

Windows PowerShell 2.0

2009年7月

Windows PowerShell 1.0

2006年11月

查找 PowerShell 版本

要检查您正在运行的 PowerShell 版本,请以管理员身份启动 Windows PowerShellPowerShell 并运行以下命令。

注意:Windows PowerShell 和 PowerShell 是不同的版本,您需要启动正确的 PowerShell 窗口并运行以下命令。

$PSVersionTable.PSVersion

如果您在 Windows PowerShell 中运行它,则结果如下。

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

请参阅下面的屏幕截图。

[玩转系统] 如何安装和更新 PowerShell 7

如果您在 PowerShell 中运行它,则结果如下。

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

请参阅下面的屏幕截图。

[玩转系统] 如何安装和更新 PowerShell 7

安装 PowerShell 7

有多种方法可以在系统上安装 PowerShell。请遵循以下方法之一。

方法一:单线

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

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

之后,您将看到可以执行的 PowerShell 7 设置向导。

[玩转系统] 如何安装和更新 PowerShell 7

确保启用所有选项。

[玩转系统] 如何安装和更新 PowerShell 7

从 PowerShell 7.2 及更高版本开始,如果您在安装向导中启用它,Microsoft 将在同一发布通道中自动更新 PowerShell 7。例如,PowerShell 7.2.x 到 7.2.y 和 7.3.x 到 7.3.y。

启用这两个选项。

[玩转系统] 如何安装和更新 PowerShell 7

完成安装。

[玩转系统] 如何安装和更新 PowerShell 7

PowerShell 7 出现在您的程序中。

[玩转系统] 如何安装和更新 PowerShell 7

方法2.从GitHub下载

转到 PowerShell GitHub 页面并下载 PowerShell 7 安装程序。

[玩转系统] 如何安装和更新 PowerShell 7

打开 PowerShell .msi 文件并执行设置向导,如上述方法所示。

方法3:WinGet(Windows包管理器)

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

注意:下载后,它将自动安装 PowerShell 7,并且您不会看到安装向导。

winget install --id Microsoft.Powershell

更新 PowerShell 7

最好在每次新版本发布时更新 PowerShell 7。

使用 winget Upgrade 命令将 PowerShell 7 更新到最新版本。

winget upgrade --id Microsoft.PowerShell

升级 PowerShell 7 的其他方法是从 GitHub 下载安装程序或运行如上所示的单行程序,然后您可以通过安装向导来更新 PowerShell。

常见问题 (FAQ)

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

安装 PowerShell 7 后,您无法在 Windows 上卸载 Windows PowerShell 5.1。它与 Windows 操作系统集成,您必须将其保留在系统上。

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

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

如何继续将 Windows PowerShell ISE 与 PowerShell 7 结合使用?

切换到 Visual Studio Code。它是一个免费、轻量级、开源、跨平台的代码编辑器。

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

PowerShell 7 优先于 Windows PowerShell 5.1,并且默认加载。

我可以在 Visual Studio Code 中在 Windows PowerShell 5.1 和 PowerShell 7 之间切换吗?

选择默认配置文件并选择 Windows PowerShell 5.1 或 PowerShell 7。

我们如何知道 PowerShell 7 支持哪些 cmdlet 和模块?

Microsoft 保留模块和 cmdlet 的发布历史记录。

为什么 Microsoft 不随 Windows 附带 PowerShell 7?

Microsoft 计划最终在 Windows 中提供 PowerShell 7,作为与 Windows PowerShell 5.1 并行的功能。但他们仍然需要制定一些细节,而且还没有具体的时间表。

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

如果可以的话,您绝对应该使用 PowerShell 7。但请确保在转换到 PowerShell 7 之前测试所有 cmdlet 和脚本。

阅读更多内容:如何连接到 Microsoft Graph PowerShell »

结论

您学习了如何安装和更新 PowerShell 7。请确保尽可能使用 PowerShell 7,因为 Microsoft 会不断更新它,并且执行速度比旧版本快得多。如果无法将某些命令和脚本移植到 PowerShell 7,请继续使用 PowerShell 5.1。

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

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯