| 用途 | 在文件中搜索关键字 |
|---|---|
| 语法 | Select-String [-Pattern] <正则> [-Path <文件/通配>] [-SimpleMatch] [-Context 前后行] |
| 要点 | 默认按正则解释 -Pattern;纯字符串搜索加 -SimpleMatch |
常用示例
常用示例
Select-String -Path C:\Logs\*.log -Pattern 'ERROR' | Select-Object -First 20
Select-String -Path app.log -Pattern 'timeout' -Context 1,2输出对象含 Filename、LineNumber、Line 属性,可管道进 Group-Object 做错误分类统计。