一、基础体验增强(强烈推荐)
1. PSReadLine
Install-Module PSReadLine -Scope CurrentUser -Force
- 命令行编辑增强:语法高亮、自动补全、历史记录搜索
- 支持多行编辑、预测性 IntelliSense
- PowerShell 7+ 已内置,但建议更新到最新版
2. posh-git
Install-Module posh-git -Scope CurrentUser
- 在提示符中显示 Git 分支/状态信息
- Git 命令的 Tab 补全
3. oh-my-posh
winget install JanDeDobbeleer.OhMyPosh -s winget
- 美化终端提示符(类似 Linux 的 oh-my-zsh)
- 支持主题、图标、多行提示
4. Terminal-Icons
Install-Module Terminal-Icons -Scope CurrentUser
- 在
ls/dir输出中显示文件/文件夹图标和颜色
二、微软官方实用工具模块
5. PowerShellGet(v3 / PSResourceGet)
Install-Module Microsoft.PowerShell.PSResourceGet -Scope CurrentUser
- 新一代包管理器,替代旧版 PowerShellGet
- 更快、更可靠的模块安装/更新体验
6. SecretManagement + SecretStore
Install-Module Microsoft.PowerShell.SecretManagement -Scope CurrentUser
Install-Module Microsoft.PowerShell.SecretStore -Scope CurrentUser
- 统一管理密码、API Key、证书等敏感信息
- 支持多种后端 Vault(Azure Key Vault、HashiCorp 等)
7. Crescendo
Install-Module Microsoft.PowerShell.Crescendo -Scope CurrentUser
- 将传统命令行工具(如 netsh、robocopy)包装为 PowerShell 原生 cmdlet
- 输出为对象而非纯文本
8. ThreadJob
Install-Module ThreadJob -Scope CurrentUser
- 轻量级后台线程任务(比 Start-Job 更快、更省资源)
- PowerShell 7+ 已内置
三、开发/运维效率模块
9. ImportExcel
Install-Module ImportExcel -Scope CurrentUser
- 无需安装 Excel 即可读写 .xlsx 文件
- 导出报表、数据分析神器
10. Pester
Install-Module Pester -Scope CurrentUser -Force
- PowerShell 官方单元测试/集成测试框架
- 脚本质量保障必备
11. PSScriptAnalyzer
Install-Module PSScriptAnalyzer -Scope CurrentUser
- 静态代码分析(类似 ESLint/Pylint)
- 检查代码规范、潜在 Bug
12. platyPS
Install-Module platyPS -Scope CurrentUser
- 用 Markdown 编写 PowerShell 帮助文档
- 生成 MAML 帮助文件
四、云 & DevOps 相关
13. Az(Azure PowerShell)
Install-Module Az -Scope CurrentUser -Repository PSGallery
- 管理 Azure 资源的官方模块
14. AWS.Tools
Install-Module AWS.Tools.Installer -Scope CurrentUser
- 管理 AWS 资源
15. PSKubernetes / kubectl 补全
# 如果用 kubectl,可启用补全
kubectl completion powershell | Out-String | Invoke-Expression
16. Docker 补全
Install-Module DockerCompletion -Scope CurrentUser
五、开发环境配置
17. VS Code + PowerShell 扩展
- 安装 VS Code 后,必装扩展:
ms-vscode.powershell(官方 PowerShell 扩展)- 提供调试、IntelliSense、代码格式化、PSScriptAnalyzer 集成
18. Windows Terminal(Windows 10/11)
winget install Microsoft.WindowsTerminal
- 多标签、GPU 加速渲染、自定义主题
- 搭配 oh-my-posh + Nerd Font 效果最佳
六、一键安装脚本参考
# 设置执行策略(管理员运行)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# 批量安装核心模块
$modules = @(
'PSReadLine',
'posh-git',
'Terminal-Icons',
'Microsoft.PowerShell.PSResourceGet',
'Microsoft.PowerShell.SecretManagement',
'Microsoft.PowerShell.SecretStore',
'ImportExcel',
'Pester',
'PSScriptAnalyzer',
'ThreadJob'
)
foreach ($m in $modules) {
Write-Host "Installing $m ..." -ForegroundColor Cyan
Install-Module $m -Scope CurrentUser -Force -AllowClobber
}
Write-Host "All done!" -ForegroundColor Green
七、Profile 配置建议
编辑 $PROFILE 文件(路径通常为 ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1):
# 加载模块
Import-Module posh-git
Import-Module Terminal-Icons
# oh-my-posh 主题
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\catppuccin_mocha.omp.json" | Invoke-Expression
# PSReadLine 配置
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# 常用别名
Set-Alias ll Get-ChildItem
Set-Alias grep Select-String
总结优先级
| 优先级 | 模块 | 用途 |
|---|---|---|
| ⭐⭐⭐ | PSReadLine | 命令行体验质变 |
| ⭐⭐⭐ | oh-my-posh + Nerd Font | 终端美化 |
| ⭐⭐⭐ | Pester | 测试保障 |
| ⭐⭐ | ImportExcel | 数据处理 |
| ⭐⭐ | SecretManagement | 安全管理 |
| ⭐⭐ | PSScriptAnalyzer | 代码质量 |
| ⭐ | Terminal-Icons / posh-git | 视觉增强 |
| ⭐ | Az / AWS.Tools | 云管理(按需) |
根据你的使用场景(系统管理、DevOps、开发、安全),可以选择性安装对应模块。如果是日常使用,前 5 个装好就能让 PowerShell 体验提升一个档次。