Skip to content

Getting Started(快速上手)

首次体验 PowerShell 的基本命令与帮助系统:

  • 发现命令与帮助:
    • Get-Command:搜索可用命令、函数、脚本、别名
    • Get-Help <Cmdlet>:查看命令用法、示例;-Online 打开网页;-Full 查看完整帮助
  • 查看系统信息:
    • Get-Process、Get-Service、Get-EventLog / Get-WinEvent
    • Get-ChildItem(ls、dir 别名):列目录
    • Get-Item / Set-Item:读写文件/注册表/环境变量等通用“提供程序”资源
  • 管道与筛选:
    • Where-Object(? 别名)筛选对象
    • Select-Object(select 别名)投影属性
    • Sort-Object(sort 别名)排序

示例:列出占用内存前 5 的进程,仅显示名称与工作集,按内存倒序。

powershell
Get-Process |
  Sort-Object -Property WorkingSet -Descending |
  Select-Object -First 5 -Property Name, Id, @{n='MemoryMB';e={[math]::Round($_.WorkingSet/1MB,2)}}

运行脚本:

  • 使用 .\script.ps1 执行当前目录脚本
  • 可能需要设置执行策略:Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

编辑器建议:

  • VS Code + PowerShell 扩展:语法高亮、IntelliSense、调试、代码片段与重构支持

本站内容仅供学习和研究使用。