什么是 Windows PowerShell?

17 Mar 2025 | 4 分钟阅读

类似的问题

  • PowerShell 的目的是什么?
  • Windows 中的 PowerShell 是什么?
  • Windows PowerShell 与命令提示符相同吗?
  • 我应该删除 Windows PowerShell 吗?
  • Windows PowerShell 是病毒吗?

答案

PowerShell 是一个由 Microsoft 开发的开源、面向对象、跨平台、任务自动化和配置管理框架。它由命令行 shell 和脚本语言组成,并且是一种比命令提示符更强大的工具。 它由 Microsoft 开发,旨在帮助 IT 专业人员配置系统并自动执行管理任务。

当它由 Microsoft 开发时,由于它对 Windows 操作系统的强大功能和控制能力,它本应取代命令提示符。管理任务由 PowerShell 中的 cmdlet 执行。 它还方便管理员完全访问 COM、WMI,并在本地和远程 Windows 系统上执行管理任务。

PowerShell 的历史

2006 年 11 月,PowerShell 的第一个版本发布,适用于 Windows XP、Windows Server 2003 和 Windows Vista。PowerShell 的最新版本是 PowerShell 7,它是 PowerShell Core 6.x 产品以及 Windows PowerShell 5.1 的产品替代品。 PowerShell 5.1 是其最后一个支持的版本,适用于 Windows Server 2008 R2、Windows Server 2012 和 Windows Server 2012 R2、Windows 7 Service Pack 1 和 Windows 8.1。

为什么它被称为 Windows PowerShell?

Microsoft 开发了 PowerShell,最初仅与 Windows 一起提供。 2016 年,Microsoft 将其开源,并在 Linux 和 macOS 上公开提供。

Windows PowerShell 使用和执行四种类型的命令

  • Cmdlet
  • PowerShell 函数
  • PowerShell 脚本
  • 可执行程序

Windows PowerShell 7 的主要功能

Microsoft 在每个新版本和更新中都扩展了 Windows PowerShell 的功能。 在这里,我们讨论其最新版本 PowerShell 7 中添加的功能。PowerShell 7.0 引入了大量新功能,例如

  • 它引入了一些新运算符
    1. 三元运算符:a? b: c
    2. 管道链运算符:|| 和 &&
    3. 空条件运算符:?? 和 ??=
  • 它构建在 .NET Core 3.1 (LTS) 之上。
  • 它引入了自动新版本通知。
  • PowerShell 7 方便您直接调用 DSC 资源。
  • 您可以轻松调查错误,因为它提供了简化的动态错误视图和用于错误调查的 Get-Error cmdlet。
  • 它提供了一个兼容性层,使用户可以在隐式 Windows PowerShell 会话中导入模块。

在 Windows 中哪里可以找到 PowerShell?

让我们看看如何在 Windows 中打开 PowerShell(启动 powerShell)。 按照下面给出的步骤

  • 单击 Windows 10 开始菜单右侧的 Cortana 搜索栏。 现在,键入关键字“powershell”,然后单击屏幕上显示的顶部结果,即 Windows PowerShell。 见下图
What is Windows PowerShell
  • 单击“Windows PowerShell”后,将打开一个新的弹出窗口。 它是 Windows PowerShell 窗口,您可以在其中运行 cmdlet(发音为 command lets)。
What is Windows PowerShell
  • 如果您想以管理员身份启动 Windows PowerShell,请右键单击搜索结果“Windows PowerShell”,然后单击 “以管理员身份运行” 见下图
What is Windows PowerShell
  • 现在,它将以管理员身份打开 Windows PowerShell。
What is Windows PowerShell

使用“运行”窗口启动 PowerShell

这是在 Windows PC 中启动 PowerShell 的最简单方法之一。 它可用于所有 Windows 版本。 使用以下步骤通过此方法运行 PowerShell

  • 同时按下键盘上的 Windows 键 + R 键。 这将打开“运行”窗口。 现在,键入 powershell 并按键盘上的 Enter 按钮。 或者,您也可以单击“确定”按钮。
What is Windows PowerShell
  • 单击“确定”按钮后,它将打开 PowerShell 窗口。
What is Windows PowerShell

从开始菜单启动 Windows PowerShell

我们还可以从 Windows 中的“开始”菜单启动 Windows PowerShell。 此方法与 Windows 7 和 Windows 10 兼容。它也可以与 Windows 8.1 中的“开始”屏幕一起使用。 按照下面给出的步骤使用此方法启动 PowerShell

  • 单击“开始”菜单,然后转到 Windows PowerShell 文件夹。 然后,展开 Windows PowerShell 文件夹,您将看到 Windows PowerShell 的图标。
What is Windows PowerShell
  • 现在,单击带圆圈的选项,它将打开 Windows PowerShell。
What is Windows PowerShell

使用其可执行文件启动 PowerShell

要通过使用其可执行文件启动 PowerShell,如果您使用的是 Windows 10 或 Windows 8.1,请打开文件资源管理器,或者使用 Windows 7,请打开 Windows 资源管理器。

对于 32 位版本的 Windows

转到:"C:\Windows\System32\WindowsPowerShell\v1.0\."

在这里,您将在 32 位上找到 powershell.exe 文件。

What is Windows PowerShell

对于 64 位版本的 Windows

转到:"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\."

在这里,您将在 64 位上找到 powershell.exe 文件。

What is Windows PowerShell

从命令提示符打开 PowerShell

请按照以下步骤操作

  • 首先,打开命令提示符。 要打开命令提示符,请在 Cortana 搜索栏上键入 cmd,然后单击 Enter 按钮。
What is Windows PowerShell
  • 打开命令提示符后,键入 start powershell,然后按键盘上的 Enter 按钮。 它将自动打开 Windows PowerShell。
What is Windows PowerShell

注意:如果您想通过使用此方法以管理员身份启动 PowerShell,您应该首先以管理员身份打开命令提示符。

What is Windows PowerShell