Skip to content

PowerShell 介绍与推荐

PowerShell 是 Microsoft 开发的任务自动化和配置管理框架,它包含一个命令行外壳程序和脚本语言。PowerShell 提供了强大的命令行工具,可以用于系统管理、自动化任务和脚本编写。

🔧 PowerShell 的特点

  • 对象管道 (Object Pipeline): 与其他 shell 不同,PowerShell 处理的是对象而不是文本,这使得数据处理更加高效和精确。
  • 丰富的命令集: PowerShell 提供了数千个内置命令(cmdlet),涵盖了从系统管理到应用程序控制的各个方面
  • 脚本编写: 支持复杂脚本编写,可以创建功能强大的自动化脚本
  • 跨平台: PowerShell 7 及以后版本支持 Windows、macOS 和 Linux

📦 推荐插件和模块

以下是一些增强 PowerShell 体验的推荐插件和模块:

1. PowerShellGet

PowerShell 模块管理工具,是 PowerShell 的核心模块之一,用于发现、安装、更新和发布 PowerShell 模块。

powershell
Install-Module -Name PowerShellGet -Force

2. PackageManagement

提供统一的包装器,用于访问和管理软件包和提供程序,例如 MSI、MSU、Chocolatey、NuGet、PowerShellGet 和 Bootstrap。

3. PSReadLine

提供高级的命令行编辑功能,包括语法高亮、命令历史搜索、多行编辑等。

powershell
Install-Module -Name PSReadLine -Force

4. posh-git

在 PowerShell 中提供 Git 状态信息的命令提示符增强功能。

powershell
Install-Module posh-git -Scope CurrentUser -Force

5. oh-my-posh

一个强大的 PowerShell 提示符自定义工具,支持多种主题和配置选项。

powershell
Install-Module oh-my-posh -Scope CurrentUser -Force

6. Terminal-Icons

为 PowerShell 提供文件和目录图标支持。

powershell
Install-Module -Name Terminal-Icons -Repository PSGallery

7. PSWindowsUpdate

用于管理 Windows 更新的 PowerShell 模块。

powershell
Install-Module -Name PSWindowsUpdate -Force

8. zoxide

一个智能的 cd 命令替代品,能够学习您的使用习惯并快速跳转到最常用的目录。

powershell
# 通过 Scoop 安装
scoop install zoxide

# 在 PowerShell 配置文件中添加初始化命令
echo 'Invoke-Expression (&zoxide init --hook pwd --cmd cd powershell)' >> $PROFILE

🛠️ Scoop 包管理器介绍

Scoop 是 Windows 上的命令行包管理器,它使安装、更新和管理应用程序变得简单。Scoop 的设计理念是"Unix/Linux 风格",它将应用程序安装在用户目录中,减少了权限问题。

安装 Scoop

打开 PowerShell 作为普通用户(不需要管理员权限),然后运行以下命令:

powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

Scoop 基本命令

命令说明
scoop install <app>安装应用程序
scoop update <app>更新特定应用程序
scoop update *更新所有应用程序
scoop uninstall <app>卸载应用程序
scoop search <app>搜索应用程序
scoop list列出已安装的应用程序
scoop status检查哪些应用程序需要更新

常用 Bucket (软件源)

Scoop 使用 "buckets" 来组织软件包,除了默认的 bucket 外,还可以添加其他 buckets:

powershell
# 添加 extras bucket (包含更多应用程序)
scoop bucket add extras

# 添加 versions bucket (包含软件的不同版本)
scoop bucket add versions

# 添加 nerd-fonts bucket (包含编程字体)
scoop bucket add nerd-fonts

推荐的 Scoop 应用

以下是一些通过 Scoop 安装的推荐应用程序:

💻 开发工具

  • git: 版本控制系统
  • nodejs: JavaScript 运行时环境
  • python: Python 编程语言
  • vscode: Visual Studio Code 编辑器
  • postman: API 测试工具

⚙️ 系统工具

  • 7zip: 文件压缩工具
  • everything: 文件搜索工具
  • wttr: 天气查询工具
  • grep: 文本搜索工具
  • sudo: 提升权限工具

🖥️ 终端增强

  • pwsh: PowerShell 核心 (跨平台)
  • oh-my-posh: PowerShell 主题引擎
  • starship: 跨 shell 提示符
  • zoxide: 智能 cd 命令
  • fzf: 模糊查找工具

使用示例

powershell
# 安装 Git
scoop install git

# 安装 Node.js
scoop install nodejs

# 安装 Visual Studio Code
scoop install vscode

# 同时安装多个应用
scoop install git nodejs python

# 查看需要更新的应用
scoop status

# 更新所有应用
scoop update *

通过 PowerShell 和 Scoop 的结合使用,Windows 用户可以享受到类似于 Unix/Linux 系统的高效命令行体验。