在 Windows 10 上安装 PowerShell 7 的方法

花旦 windows教程 12

几个月前,微软发布了 PowerShell 7 的最终版本,支持 Windows、macOS 和 Linux。PowerShell 是跨平台的自动化与配置管理框架,也是近年来 Windows 操作系统内置的工具之一。

PowerShell 7 带来了许多新特性,包括管道并行化、新的运算符和 cmdlet。虽然 PowerShell 7 已经发布好几个月了,但微软还没有把 Windows 10 内置的 PowerShell 升级到 7 版本。

在 Windows 10 上安装 PowerShell 7 的方法-第1张图片-致知笔记
PowerShell 7

如何查看 PowerShell 版本?

在下载并安装新版本之前,你可能想知道 Windows 10 自带的是哪个版本的 PowerShell。方法如下:

1. 通过“开始”菜单或任务栏搜索打开 PowerShell。

2. 在 PowerShell 窗口中,复制并粘贴下面的命令,然后按回车键查看当前版本:

Get-Host | Select-Object Version

在 Windows 10 上安装 PowerShell 7 的方法-第2张图片-致知笔记
执行命令查看版本

或者:

$PSVersionTable

在 Windows 10 上安装 PowerShell 7 的方法-第3张图片-致知笔记
用 $PSVersionTable 查看版本

安装新版本会升级内置 PowerShell 吗?

不会。如果你按照下面的方法安装 PowerShell 7,它会与内置的 PowerShell 并列安装,也就是说 PowerShell 7 会被安装到一个新的目录中,不会动到内置的 PowerShell。这意味着你可以同时使用内置版本和新安装的版本。

注意:如果你之前安装过 PowerShell 6.x,那么 PowerShell 7.x 属于就地升级。

PowerShell 7.x 在 Windows 10 中的安装位置

PowerShell 7.x 会被安装到 Windows 10 中的以下目录:

C:\Program Files\PowerShell

如何在 Windows 10 中安装 PowerShell 7

1. 访问 GitHub 的该页面,获取 .msi 安装文件。注意,32 位和 64 位分别有不同的文件。下载 .msi 文件时,请务必下载稳定版(stable release)。

在 Windows 10 上安装 PowerShell 7 的方法-第4张图片-致知笔记
下载 MSI 安装文件

2. 运行下载好的 .msi 文件,按照简单的提示完成 PowerShell 7 的安装。

在 Windows 10 上安装 PowerShell 7 的方法-第5张图片-致知笔记
运行安装程序
在 Windows 10 上安装 PowerShell 7 的方法-第6张图片-致知笔记
安装向导
在 Windows 10 上安装 PowerShell 7 的方法-第7张图片-致知笔记
选择安装选项
在 Windows 10 上安装 PowerShell 7 的方法-第8张图片-致知笔记
安装进行中
在 Windows 10 上安装 PowerShell 7 的方法-第6张图片-致知笔记
安装向导
在 Windows 10 上安装 PowerShell 7 的方法-第7张图片-致知笔记
选择安装选项
在 Windows 10 上安装 PowerShell 7 的方法-第8张图片-致知笔记
安装进行中

从 PowerShell 窗口安装 PowerShell 7

1. 以管理员身份打开 Windows PowerShell。方法是右键点击“开始”按钮,然后点击“Windows PowerShell(管理员)”选项。

在 Windows 10 上安装 PowerShell 7 的方法-第12张图片-致知笔记
以管理员身份运行

2. 执行以下命令,下载最新版 PowerShell 并运行安装程序:

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

在 Windows 10 上安装 PowerShell 7 的方法-第13张图片-致知笔记
执行安装命令
在 Windows 10 上安装 PowerShell 7 的方法-第14张图片-致知笔记
启动安装向导

3. 当出现如下安装界面时,点击“下一步(Next)”按钮。

在 Windows 10 上安装 PowerShell 7 的方法-第15张图片-致知笔记
点击下一步

4. 出现该界面时,选择想要添加/安装的功能(都一目了然),然后点击“下一步”;再次点击“安装(Install)”按钮完成安装。完成后点击“完成(Finish)”按钮。

在 Windows 10 上安装 PowerShell 7 的方法-第16张图片-致知笔记
选择功能
在 Windows 10 上安装 PowerShell 7 的方法-第17张图片-致知笔记
确认安装
在 Windows 10 上安装 PowerShell 7 的方法-第18张图片-致知笔记
安装完成
在 Windows 10 上安装 PowerShell 7 的方法-第17张图片-致知笔记
确认安装
在 Windows 10 上安装 PowerShell 7 的方法-第18张图片-致知笔记
安装完成

如何打开 PowerShell 7?

如果你用“PowerShell”这个关键词启动,开始菜单/任务栏搜索会打开内置的旧版 PowerShell。要启动 PowerShell 7,请键入 pwsh 然后按回车键。

PowerShell 窗口会显示版本号,你可以核对一下,确保打开的确实是 PowerShell 7。

在 Windows 10 上安装 PowerShell 7 的方法-第21张图片-致知笔记
输入 pwsh 启动

如何在 Windows 10 中卸载 PowerShell 7

注意,卸载 PowerShell 7 并不会移除内置的 Windows PowerShell 工具。

1. 在开始/任务栏搜索框中输入 appwiz.cpl 并按回车键,打开“程序和功能”窗口。

2. 找到 PowerShell 7 条目,右键点击它,然后选择“卸载(Uninstall)”选项。

在 Windows 10 上安装 PowerShell 7 的方法-第22张图片-致知笔记
卸载 PowerShell 7

可以在 Mac 或 macOS 上安装 PowerShell 7 吗?

可以,PowerShell 同样可以安装在 macOS 上。请前往上面提到的下载页面,获取 .pkg 文件。

在 Windows 10 上安装 PowerShell 7 的方法-第23张图片-致知笔记
macOS 下载

标签: Windows 10 PowerShell 7 安装教程

抱歉,评论功能暂时关闭!