# PowerShell

PowerShell 横跨 Windows、Linux 和 macOS，将三类组件打包在一起，用于实现任务自动化：一个从命令行驱动的 shell、一门用于编写脚本的语言，以及一个用于管理配置的框架。<sup>[1](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5)</sup> 它的标志性特征是对象管道：命令之间传递的是结构化的 .NET 对象，而不是一行行文本，这就免去了基于文本的 shell 在命令之间所需的大量字符串解析。<sup>[2](https://www.johndcook.com/blog/2009/06/09/comparing-the-unix-and-powershell-pipelines/)</sup> 它最初由微软开发，代号莫纳德，用于 Windows 管理，到 6.0 版时成为开源、跨平台的项目，如今已是整个微软生态（包括 Azure）中的标准自动化层。<sup>[3](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-71?view=powershell-7.1)</sup><sup> • </sup><sup>[4](https://www.techradar.com/pro/50-microsoft-tools-you-can-use-for-free-just-in-time-for-build-2026)</sup>

| 关键事实 | 详情 |
|---|---|
| 它是什么 | 用于在 Windows、Linux 和 macOS 上实现任务自动化的命令行 shell、脚本语言和配置管理框架<sup>[1](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5)</sup> |
| 管道模型 | 命令之间交换的是 .NET 对象，而非文本；一个日期输出是 .NET 日期对象，而不是字符串<sup>[2](https://www.johndcook.com/blog/2009/06/09/comparing-the-unix-and-powershell-pipelines/)</sup> |
| 起源 | 由杰弗里·斯诺弗（Jeffrey Snover）构思设计，2002 年起以莫纳德为代号；在 2003 年专业开发者大会上公布<sup>[5](https://devblogs.microsoft.com/powershell/monad-manifesto-the-origin-of-windows-powershell/)</sup><sup> • </sup><sup>[6](https://www.leeholmes.com/download-the-official-windows-powershell-1-0-release/)</sup> |
| 首次发布 | Windows PowerShell 1.0 于 2006 年 11 月 14 日发布到 Web（Release to Web）<sup>[6](https://www.leeholmes.com/download-the-official-windows-powershell-1-0-release/)</sup> |
| 跨平台转折 | PowerShell 6.0 基于 .NET Core 2.0 开源，可在 Windows、macOS 和 Linux 上运行<sup>[3](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-71?view=powershell-7.1)</sup> |
| 当前版本 | LTS 版本 7.6.6，基于 .NET 10 构建；上一个 LTS 版本 7.4.20 支持至 2026 年 11 月 10 日<sup>[7](https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.5)</sup><sup> • </sup><sup>[8](https://devblogs.microsoft.com/powershell/announcing-powershell-7-6/)</sup> |
| 安全态势 | 执行策略、受限语言模式、脚本块日志记录和 AMSI 集成；被攻击者滥用时，MITRE 将其列为技术 T1059.001<sup>[9](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7)</sup><sup> • </sup><sup>[10](https://attack.mitre.org/techniques/T1059/001/)</sup> |

## 历史

2002 年 12 月下旬，一位 [Slashdot](https://www.edgepedia.org/zh/slashdot) 读者发现了一则招聘启事，招聘“微软的下一代 Shell”，PowerShell 由此进入公众视野。大约一年后，微软在 2003 年专业开发者大会上公布了这个代号为莫纳德的项目，随后在 2004 年 9 月发布了第一个真正公开的预览版。<sup>[6](https://www.leeholmes.com/download-the-official-windows-powershell-1-0-release/)</sup> 设计目标写在杰弗里·斯诺弗的《Monad 宣言》中，即打造一个用于管理 Windows 的下一代命令驱动平台——当时 Windows 管理还缺少可与 Unix shell 相媲美的脚本环境。<sup>[5](https://devblogs.microsoft.com/powershell/monad-manifesto-the-origin-of-windows-powershell/)</sup>

Beta 阶段从 2005 年 6 月的莫纳德 Beta 1 一直延续到 2006 年 3 月的 Beta 3.1。2006 年 4 月，微软宣布莫纳德将更名为 PowerShell，2006 年 4 月 25 日发布候选版 1（Release Candidate 1），可执行文件更名为 PowerShell.exe，脚本扩展名改为 .ps1。<sup>[6](https://www.leeholmes.com/download-the-official-windows-powershell-1-0-release/)</sup><sup> • </sup><sup>[11](https://catalogimages.wiley.com/images/db/pdf/9781118013861.excerpt.pdf)</sup> Windows PowerShell 1.0 于 2006 年 11 月 14 日发布到 Web，由鲍勃·穆格利亚（Bob Muglia）和杰弗里·斯诺弗在 IT Forum 上宣布。<sup>[6](https://www.leeholmes.com/download-the-official-windows-powershell-1-0-release/)</sup> Exchange 2007 以 Windows PowerShell 为核心构建其整个管理体验，这早早预示了微软产品通过该 shell 暴露其管理功能的模式。<sup>[12](https://devblogs.microsoft.com/powershell/windows-powershell-monad-has-arrived/)</sup>

2.0 版于 2009 年问世，内置于 [Windows 7](https://www.edgepedia.org/zh/windows-7) 和 [Windows Server 2008 R2](https://www.edgepedia.org/zh/windows-server-2008-r2) 中。<sup>[11](https://catalogimages.wiley.com/images/db/pdf/9781118013861.excerpt.pdf)</sup> 更大的断裂出现在 PowerShell 6.0：该项目转为开源，并从 .NET Framework 迁移到 .NET Core 2.0；这一转变使 PowerShell 得以在 Windows、macOS 和 Linux 上运行。<sup>[3](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-71?view=powershell-7.1)</sup> Windows PowerShell 5.1 是最后一个仅限 Windows 的版本，仍基于 .NET Framework 4.5 构建，作为 Windows 组件随系统提供；而现代的 7.x 系列则作为独立应用程序安装。<sup>[3](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-71?view=powershell-7.1)</sup>

## 对象管道

PowerShell 管道是由管道运算符 `|` 连接起来的一系列命令；每个运算符把前一条命令的结果发送给下一条。<sup>[13](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.5)</sup> 在 Unix shell 中，命令之间流动的数据是文本，因此管道常常需要 grep、sed 或 awk 之类的中间工具来衔接输出与输入格式。PowerShell 命令则直接输出 .NET 对象：产生日期的命令返回一个 .NET 日期对象，接收命令拿到的是这个对象本身，而不是它的字符串表示。<sup>[2](https://www.johndcook.com/blog/2009/06/09/comparing-the-unix-and-powershell-pipelines/)</sup>

这些命令本身称为 cmdlet，是 PowerShell 原生的命令，而非独立的可执行文件，它们被收进按需加载的模块中。cmdlet 遵循“动词-名词”的命名约定，例如 `Get-Command`，其中动词指明动作，[名词](https://www.edgepedia.org/zh/noun)指明资源。<sup>[14](https://learn.microsoft.com/en-us/powershell/scripting/powershell-commands)</sup> 提供程序（Provider）把同样的导航模型扩展到非文件系统的数据存储：注册表显示为 `HKLM:` 和 `HKCU:` 驱动器，证书显示为 `Cert:`，环境变量显示为 `Env:`，它们都能用同一套提供程序 cmdlet 来管理。<sup>[15](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_providers?view=powershell-7.6)</sup>

该语言可通过函数、类、脚本和模块进行扩展，并内置对 CSV、JSON 和 XML 等常见数据格式的支持。<sup>[1](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5)</sup> 一个模块生态把它延伸到几乎任何技术领域：微软发布了面向 Azure、Windows、Exchange 和 SQL 的模块，第三方则发布了面向 AWS、VMware 和 Oracle Cloud 的模块。PowerShell 期望状态配置（Desired State Configuration，DSC）以代码形式加入了声明式配置，可通过推送或拉取部署来强制执行设置，并报告配置漂移。<sup>[1](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5)</sup> Az 模块通过 `Install-Module Az` 安装，为每一项主要的 Azure 服务提供 cmdlet。<sup>[4](https://www.techradar.com/pro/50-microsoft-tools-you-can-use-for-free-just-in-time-for-build-2026)</sup>

## 版本与支持生命周期

PowerShell 遵循微软现代生命周期策略，其支持终止日期遵循各版本所基于的 .NET 版本的 .NET 支持策略。它有两类发布轨道：稳定版（Stable）可以包含新功能，在下一个 LTS 版本发布后约支持六个月；长期服务版（LTS）与 .NET 的 LTS 版本对齐，只接收关键安全更新和服务修复。微软只支持某个版本的最新更新版本。<sup>[7](https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.5)</sup>

PowerShell 7.6 是当前的 LTS 版本，于 2026 年 3 月 18 日正式发布，基于 .NET 10（LTS）构建。<sup>[8](https://devblogs.microsoft.com/powershell/announcing-powershell-7-6/)</sup> 其更新包括修订后的核心模块（PSReadLine、Microsoft.PowerShell.PSResourceGet、Microsoft.PowerShell.ThreadJob）、引擎可靠性修复、原生命令处理改进以及 Tab 键补全改进。<sup>[8](https://devblogs.microsoft.com/powershell/announcing-powershell-7-6/)</sup><sup> • </sup><sup>[16](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-76?view=powershell-7.6)</sup> 上一个 LTS 版本 7.4.20 的支持将持续到 2026 年 11 月 10 日。<sup>[7](https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.5)</sup> 在打包方面，从 2026 年 4 月的 PowerShell 7.7-preview.1 开始，MSIX 包成为 Windows 上的主要安装方式，新版本不再提供 MSI 安装程序；这一变化源于 MSIX 的声明式服务模型以及 MSI 在可访问性方面的不足。<sup>[17](https://devblogs.microsoft.com/powershell/powershell-msi-deprecation/)</sup>

## 安全模型

PowerShell 内置了若干旨在提升脚本环境安全性的功能。<sup>[18](https://learn.microsoft.com/en-us/powershell/scripting/security/security-features?view=powershell-7.5)</sup> 执行策略控制 PowerShell 在何种条件下加载配置文件并运行脚本，有助于阻止恶意脚本的执行。微软明确指出，它并非安全边界，而是纵深防御：用户可以在命令行直接键入脚本内容来绕过它，其目的是设定基本规则、防止无意的违规。在 Windows 上，默认策略是 RemoteSigned，它要求从互联网下载的脚本具有受信任发布者的数字签名，同时允许本地脚本运行；AllSigned 要求包括本地编写的脚本在内的所有脚本都有签名；Bypass 则不做任何拦截。在非 Windows 平台上，默认策略是 Unrestricted 且无法更改，因为这些平台不实现 Windows 安全区域。<sup>[9](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7)</sup>

语言模式限制会话能做什么。受限语言（ConstrainedLanguage）模式允许所有 cmdlet 和语言的一个子集，但限制可使用的对象类型，并可通过 AppLocker 或会话配置强制执行。<sup>[19](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-7.6)</sup> 从 PowerShell 5.1 开始，在 [Windows 10](https://www.edgepedia.org/zh/windows-10) 及更高版本上运行的 PowerShell 会把所有脚本块传递给 AMSI（反恶意软件扫描接口），脚本块日志记录则把解码后的内容记录到 Microsoft-Windows-PowerShell/Operational 事件日志中。<sup>[20](https://learn.microsoft.com/en-us/powershell/scripting/learn/security-features?view=powershell-7.4)</sup>

## 管理员与攻击者的使用

PowerShell 默认安装在 Windows 机器上，是 Windows 系统管理的核心技能，用于本地管理、脚本编写以及管理 [Microsoft 365](https://www.edgepedia.org/zh/microsoft-365) 服务。<sup>[21](https://arxiv.org/abs/1804.04177)</sup><sup> • </sup><sup>[22](https://microsoftlearning.github.io/AZ-040T00-Automating-Administration-with-PowerShell/)</sup> 同样的特性也让它对攻击者颇具吸引力。[MITRE ATT&CK](https://www.edgepedia.org/zh/mitre-att-and-ck) 将滥用 PowerShell 命令和脚本进行执行的行为列为技术 T1059.001，并指出攻击者利用它来发现信息和执行代码，包括下载额外载荷的无文件攻击链。<sup>[10](https://attack.mitre.org/techniques/T1059/001/)</sup> 由于 PowerShell 命令可以动态生成、从内存中执行，并可进行编码或混淆，对已执行代码进行日志记录和取证分析十分困难，安全研究人员报告称，它在[无文件恶意软件](https://www.edgepedia.org/zh/fileless-malware)（如挖矿脚本）中被大量使用。<sup>[21](https://arxiv.org/abs/1804.04177)</sup><sup> • </sup><sup>[23](https://arxiv.org/abs/2401.07995)</sup> 建议的缓解措施包括：将执行策略限制为仅允许已签名脚本、通过受限语言模式实施应用程序控制，以及使用 PowerShell JEA（恰够管理，Just Enough Administration）对远程管理进行沙箱隔离。<sup>[10](https://attack.mitre.org/techniques/T1059/001/)</sup>

## References

1. [What is PowerShell? Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.5)
2. [Comparing the Unix and PowerShell pipelines, John D. Cook (2009)](https://www.johndcook.com/blog/2009/06/09/comparing-the-unix-and-powershell-pipelines/)
3. [Differences between Windows PowerShell 5.1 and PowerShell 7.x, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-71?view=powershell-7.1)
4. [50 Microsoft tools you can use for free, TechRadar (2026)](https://www.techradar.com/pro/50-microsoft-tools-you-can-use-for-free-just-in-time-for-build-2026)
5. [Monad Manifesto – the Origin of Windows PowerShell, PowerShell Team blog](https://devblogs.microsoft.com/powershell/monad-manifesto-the-origin-of-windows-powershell/)
6. [Download the Official Windows PowerShell 1.0 Release!, Lee Holmes (2006)](https://www.leeholmes.com/download-the-official-windows-powershell-1-0-release/)
7. [PowerShell Support Lifecycle, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle?view=powershell-7.5)
8. [Announcing PowerShell 7.6 (LTS) GA Release, PowerShell Team blog (2026)](https://devblogs.microsoft.com/powershell/announcing-powershell-7-6/)
9. [about_Execution_Policies, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7)
10. [Command and Scripting Interpreter: PowerShell (T1059.001), MITRE ATT&CK](https://attack.mitre.org/techniques/T1059/001/)
11. [Windows PowerShell 2.0 excerpt, Wiley](https://catalogimages.wiley.com/images/db/pdf/9781118013861.excerpt.pdf)
12. [Windows PowerShell (Monad) Has Arrived, PowerShell Team blog (2006)](https://devblogs.microsoft.com/powershell/windows-powershell-monad-has-arrived/)
13. [about_Pipelines, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.5)
14. [What is a PowerShell command?, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/powershell-commands)
15. [about_Providers, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_providers?view=powershell-7.6)
16. [What's New in PowerShell 7.6, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-76?view=powershell-7.6)
17. [PowerShell MSI package deprecation and preview updates, PowerShell Team blog (2026)](https://devblogs.microsoft.com/powershell/powershell-msi-deprecation/)
18. [PowerShell security features, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/security/security-features?view=powershell-7.5)
19. [about_Language_Modes, Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-7.6)
20. [PowerShell security features (7.4), Microsoft Learn](https://learn.microsoft.com/en-us/powershell/scripting/learn/security-features?view=powershell-7.4)
21. [Detecting Malicious PowerShell Commands using Deep Neural Networks, arXiv](https://arxiv.org/abs/1804.04177)
22. [AZ-040T00: Automating Administration with PowerShell, Microsoft Learning](https://microsoftlearning.github.io/AZ-040T00-Automating-Administration-with-PowerShell/)
23. [The Pulse of Fileless Cryptojacking Attacks: Malicious PowerShell Scripts, arXiv](https://arxiv.org/abs/2401.07995)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 19, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 19, 2026; Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages › C-family and imperative languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/powershell

English original: https://www.edgepedia.org/powershell
