Windows 11 将 Windows PowerShell 从 5 “升级“到 7 版本
首先,要了解 Windows PowerShell 和 PowerShell 的区别,下面是 AI 给的答复:
Windows PowerShell 和 PowerShell(通常指 PowerShell 7+)有一些显著的区别,主要体现在以下几个方面:
1. 平台支持
- Windows PowerShell:最初是专门为 Windows 操作系统设计的,基于 .NET Framework。
- PowerShell:PowerShell 7+(即现代版本)是跨平台的,基于 .NET Core(现为 .NET 5 及更高版本),支持 Windows、macOS 和 Linux。
2. 版本
- Windows PowerShell:最新版本为 PowerShell 5.1,是 Windows 上的默认脚本语言。
- PowerShell:从 PowerShell 7 开始,逐渐取代了 Windows PowerShell,增加了许多新特性并且能够运行在多个平台上。
3. 兼容性
- Windows PowerShell:与较旧的脚本和模块兼容,支持一些专为 Windows 环境设计的功能(例如 WMI、COM 对象等)。
- PowerShell:PowerShell 7+ 主要面向跨平台运行,因此一些 Windows 特有的功能(如 WMI、注册表操作)可能不完全适用于其他平台,但仍然有很多新的功能、改进和模块支持。
4. 性能
- Windows PowerShell:由于基于 .NET Framework,性能可能不如 PowerShell 7+。
- PowerShell:基于 .NET Core(后来的 .NET 5+),在许多方面都进行了性能优化,尤其是跨平台支持和对新技术的适配。
5. 新特性
6. 模块兼容性
- Windows PowerShell:主要兼容以 Windows 为目标的模块。
- PowerShell:为跨平台设计,支持更多来自不同操作系统的模块,并且可以兼容大量的现代化模块。
7. 命令行工具
- Windows PowerShell:内置了与 Windows 操作系统的深度集成,像是注册表、事件日志和 WMI。
- PowerShell:在 PowerShell 7 中,这些工具可能不完全支持跨平台环境,但增加了很多新的命令和 API。
总结
- Windows PowerShell 是传统的 Windows 环境专用工具,基于 .NET Framework,功能丰富但局限于 Windows 系统。
- PowerShell(从 7 版本开始)是跨平台的,基于 .NET Core 或更高版本,提供更好的性能和跨平台支持,适应现代 DevOps 和云计算需求。
如果你是在考虑迁移到跨平台环境,或者使用新功能,建议转向 PowerShell 7+。
既然 AI 都建议升级至 PowerShell 7+
了,那么,如何升级?
本教程以 Windows 11 为例。
- 打开终端(Windows 终端),在界面上输入命令,查看当前的终端的版本信息:
$PSVersionTable.PSVersion
# 若为下述信息,则为 5
Major Minor Build Revision
----- ----- ----- --------
5 1 26100 4768
# 若为下述信息,则为 7
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 5 2
# 又或者
$PSVersionTable.PSEdition
# 若为 Core,则为 PowerShell 7
# 若为 Desktop,则为 PowerShell 5
- 安装
PowerShell 7
通过命令行方式:
# Microsoft.PowerShell
winget install Microsoft.PowerShell
通过安装包方式:
https://github.com/PowerShell/PowerShell/releases
- 将 Windows 终端设置默认终端为
PowerShell 7
。
打开 Windows 终端
后,点击“下三角”标志,再点“设置”。
或 打开 Windows 终端
后,点击 Ctrl + ,
快捷键进入设置。


点击“默认配置文件”的三角标,选择 PowerShell
,再点击“保存”即可。后续再点开“Windows 终端”,默认就是使用 PowerShell 7
作为运行器。

若想快速启动 PowerShell 7:
Win + R
,输入 pwsh
,回车。
Win
,输入 pwsh
,回车。