Windows 排障命令速查
cmd 与 PowerShell 两套常用命令,按场景分组。
网络
| 命令 | 用途 |
|---|---|
ipconfig /all | 全部网卡与地址 |
ipconfig /flushdns | 清 DNS 缓存 |
ping -n 10 <host> | 连通与丢包 |
tracert <host> | 路由 |
netstat -ano | 连接与 PID |
Get-NetTCPConnection | 连接(PowerShell) |
Test-NetConnection <host> -Port 443 | 端口可达 |
Resolve-DnsName example.com | 解析 |
Get-NetIPConfiguration | 地址与网关 |
系统与进程
| 命令 | 用途 | |
|---|---|---|
tasklist /svc | 进程与服务 | |
| `Get-Process | Sort CPU -Desc` | CPU 排序 |
| `Get-Service | Where Status -eq 'Stopped'` | 停止的服务 |
Get-WinEvent -LogName System -MaxEvents 50 | 系统日志 | |
Get-CimInstance Win32_LogicalDisk | 磁盘空间 | |
Get-CimInstance Win32_OperatingSystem | 内存与启动时间 |
文件与校验
| 命令 | 用途 |
|---|---|
robocopy src dst /E /COPYALL | 目录同步 |
Get-FileHash file -Algorithm SHA256 | 哈希 |
Get-ChildItem -Recurse -File | 递归列文件 |
takeown / icacls | 属主与权限 |
修复
| 命令 | 用途 |
|---|---|
sfc /scannow | 系统文件检查 |
DISM /Online /Cleanup-Image /RestoreHealth | 组件修复 |
chkdsk C: /f | 磁盘检查(需重启) |
Reset-NetAdapter | 重置网卡 |
路径通配符
PowerShell 的 -Path 会展开 [ ]、*、?。真实路径用 -LiteralPath,否则文件名带方括号会匹配失败。
编码
Out-File 与 > 默认不是 UTF-8,且会把换行改成 CRLF。给 Excel 看用 utf8BOM,给程序解析用 utf8,精确控制用:
powershell
[IO.File]::WriteAllText($p, $s, (New-Object Text.UTF8Encoding $false))使用说明:速查内容按常见发行版与主流版本整理,命令参数以
man 与官方文档为准;涉及容量与功耗的数字为标称值换算,实际会有差异。