发现与帮助
Get-Command [<name>]按名称、别名或通配符发现命令——堪称 PowerShell 里的 man。
-Module <module>;-Noun / -Verb;-ParameterType;-All
Get-Command -Noun Service | Format-Table Name, ModuleGet-Help <cmdlet> [-Examples|-Detailed|-Full]查看 cmdlet 帮助:简介、语法、参数、示例。
-Examples;-Detailed;-Full;-Online 打开浏览器;-ShowWindow 图形窗口
Get-Help Get-Process -ExamplesGet-Module [-ListAvailable]列出当前会话已加载(或可用)的模块。
-ListAvailable;-All;-Name 过滤
Get-Module -ListAvailable | Sort-Object Name导航与文件系统
Set-Location / Get-Location / pwd切换或打印当前工作目录。
Set-Location C:\projects\app; Get-LocationGet-ChildItem (alias ls/dir)列出文件与子目录(-Recurse 递归)。
-Recurse;-Force 显示隐藏;-Filter <pattern>;-File / -Directory;-Depth
Get-ChildItem -Recurse -File -Filter *.log | Sort-Object Length -Descending | Select-Object -First 10New-Item -ItemType File/Directory <path>新建文件或目录(默认:文件)。
-Force 覆盖/创建父目录;-ItemType File|Directory|SymbolicLink;-Value 写入内容
New-Item -ItemType Directory -Path logs/2026 | Out-NullRemove-Item (alias rm/del)删除文件、目录、注册表键或变量。
-Recurse;-Force;-Confirm:\$false 跳过确认提示
Remove-Item -Recurse -Force build/, node_modules/Copy-Item / Move-Item / Rename-Item复制、移动或重命名文件系统项。
-Recurse;-Force;-To;-Exclude / -Include 过滤
Copy-Item -Recurse dist\* \\deploy\shares\app\Get-Content / Set-Content / Add-Content读取或写入文件内容(Get-Content + -Tail 类似 Unix 的 tail)。
-Tail N;-Wait 跟踪;-TotalCount N;-Encoding utf8/ASCII
Get-Content -Path app.log -Tail 50 -WaitTest-Path / Resolve-Path检查路径是否存在(文件、目录、注册表),或解析通配符。
-PathType Container|Leaf;-IsValid
if (Test-Path .\node_modules) { Remove-Item -Recurse .\node_modules }管道与对象
Where-Object (alias ?)按属性或脚本块过滤管道中的对象。
-Property / -Value 模式匹配;-Like / -EQ / -GT ...;-CContains / -In
Get-Process | Where-Object { $_.WorkingSet64 -gt 200MB }Select-Object (alias select)挑选指定属性、去重,或取前 N 条。
-Property 属性名;-First / -Last N;-Skip N;-Unique;-ExpandProperty
Get-Service | Select-Object Name, Status, StartType | Format-TableForEach-Object (alias %)对管道中流入的每个对象执行一次操作。
-Begin / -Process / -End;PS7+ 支持 -Parallel
Get-ChildItem *.csv | ForEach-Object { Import-Csv $_ | Group-Object Level }Sort-Object (alias sort)按一个或多个属性对管道对象排序。
-Property;-Descending
Get-ChildItem | Sort-Object -Property Length -Descending | Select -First 5Group-Object (alias group)按某个属性的值分组;-NoElement 只输出每组的计数。
-Property;-NoElement;-CaseSensitive
Get-Content app.log | Group-Object | Sort-Object Count -DescendingMeasure-Object (alias measure)对某个属性计算数值统计(count、sum、min/max/avg)。
-Sum / -Average / -Minimum / -Maximum;-Line / -Word / -Character 用于文本
Get-ChildItem -File -Recurse | Measure-Object -Property Length -Sum格式化
Format-Table / Format-List (ft / fl)将管道对象渲染为表格或列表——仅用于展示。
-AutoSize;-Wrap;-GroupBy;-Property 子集
Get-Process | Format-Table Name, Id, @{n='Mem(MB)';e={[Math]::Round($_.WorkingSet64/1MB,1)}} -AutoSizeOut-File / Set-Content / Tee-Object将输出写入文件;Tee-Object 同时写入文件和管道。
Get-Service | Tee-Object -FilePath services.txt | Where-Object { $_.Status -eq 'Running' }字符串与变量
Select-String (alias sls)相当于 grep——查找匹配模式的行(支持正则)。
-Path;-Pattern;-SimpleMatch;-CaseSensitive;-Context N
Select-String -Path src\**\*.ts -Pattern 'TODO' -CaseSensitive:\$falseSet-Variable (alias set/sv)定义会话级或环境变量。
-Name;-Value;-Scope Global|Local|Script;-PassThru
Set-Variable -Name regions -Value @('eastus','westus') -Scope GlobalGet-Variable / $env:列出或读取变量;通过 $env: 驱动器读写进程环境。
$env:DATABASE_URL = 'postgres://localhost/dev'; Get-Variable | Out-GridViewGet-Alias / Set-Alias列出或自定义 cmdlet 快捷方式。
Set-Alias -Name grep -Value Select-String -Option ReadOnly -Scope Global进程与服务
Get-Process / Start-Process / Stop-Process查看、启动或停止本地进程(Stop-Process 即 kill)。
-Name;-Id;-FileVersionInfo;-PassThru;-Force 用于强制 kill
Get-Process node | Sort-Object -Property WorkingSet64 -Descending | Select -First 5Get-Service / Start-Service / Stop-Service查看、启动或停止 Windows 服务。
-Name;-DisplayName;-Status Running|Stopped
Get-Service | Where-Object Status -eq Stopped | Format-Table Name, StartupType网络
Test-NetConnection <host>诊断 TCP 连通性、延迟,并可配合 -Port 检查端口可达性。
-Port;-InformationLevel Detailed;-DiagnoseRouting
Test-NetConnection api.example.com -Port 443Invoke-WebRequest / Invoke-RestMethodHTTP 客户端(RestMethod 自动把 JSON 解析为对象)。
-Method GET/POST/PUT/DELETE;-Headers @{...};-Body (json);-OutFile path;-SkipHttpRedirect;-UseBasicParsing
Invoke-RestMethod -Uri https://api.github.com/repos/powershell/powershell/releases/latest | Select-Object tag_name, html_urlResolve-DnsName / Get-NetIPAddress解析 DNS 记录,查看本机 IP 配置。
-Type A/AAAA/MX/CNAME;-Server 8.8.8.8;-AddressFamily IPv4/IPv6
Resolve-DnsName example.com -Type MX远程与模块
Enter-PSSession / Invoke-Command在远程机器上启动会话或执行命令(WinRM / SSH)。
-ComputerName / -HostName;-Credential;-ConfigurationName;-FilePath
Invoke-Command -ComputerName web01,web02 -FilePath .\deploy.ps1Import-Module / Find-Module / Install-Module把模块加载到当前会话,或从仓库获取模块。
-Force 重新加载;-Scope Global/CurrentUser;-AcceptLicense;-AllowClobber
Install-Module -Name Az -Scope CurrentUser -AcceptLicenseGet-Module / Remove-Module列出已加载的模块,或从当前会话卸载一个模块。
Get-Module | Format-Table Name, Version, ExportedCommands.Count系统
Get-Date / Set-Date读取或设置当前日期/时间,支持丰富的格式化选项。
-Format;-UFormat;-DisplayHint;-Culture
Get-Date -Format 'yyyy-MM-dd HH:mm:ss'Get-CimInstance Win32_OperatingSystem通过 CIM/WMI 获取硬件/系统信息(内存、磁盘、OS、BIOS 等)。
-ClassName;-ComputerName;-Filter 查询
Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='C:'" | Select DeviceID, @{n='FreeGB';e={[Math]::Round($_.FreeSpace/1GB,2)}}Get-History / Invoke-History (alias h/r)在当前会话中重放最近执行过的命令。
-Count N;-Id N 重新执行指定条目
Get-History | Where-Object CommandLine -like 'Get-*' | Invoke-History$PROFILE / Update-Help编辑你的 profile(启动脚本)并刷新 cmdlet 帮助。
notepad $PROFILE; Update-Help -Force速查页版本 1.0.0
适用于 PowerShell 7+