语法
Select-String
[-Culture <String>]
[-Pattern] <String[]>
[-Path] <String[]>
[-SimpleMatch]
[-CaseSensitive]
[-Quiet]
[-List]
[-NoEmphasis]
[-Include <String[]>]
[-Exclude <String[]>]
[-NotMatch]
[-AllMatches]
[-Encoding <Encoding>]
[-Context <Int32[]>]
[<CommonParameters>]
Demo1:查找区分大小写的匹配项
'Hello', 'HELLO' | Select-String -Pattern 'HELLO' -CaseSensitive -SimpleMatch
Demo2:查找文本文件中的匹配项
Select-String -Path .\*.txt -Pattern 'Get-'
Demo3:查找与模式不匹配的字符串
Select-String -Path .\Command.txt -Pattern 'Get', 'Set' -NotMatch
Demo4:把匹配结果输出为文件
Select-String -Path .\Command.txt -Pattern 'Get', 'Set' | Out-File 'C:\match.txt'
Demo5:匹配多个关键字
'a','afsss','dd','fff','ggg' | Select-String -Pattern '[a-zA-Z]+(sss|ggg)'
References:
Select-String