<p>What's the DOS FINDSTR equivalent for <a href="http://en.wikipedia.org/wiki/Windows_PowerShell" rel="noreferrer">PowerShell</a>? I need to search a bunch of log files for "ERROR".</p>

[{'answer_id': 14724, 'author': 'Monroecheeseman', 'author_id': 1351, 'author_profile': 'https://Stackoverflow.com/users/1351', 'pm_score': 5, 'selected': False, 'text': '<p>Here\'s the quick answer </p>\n\n<pre><code>Get-ChildItem -Recurse -Include *.log | select-string ERROR \n</code></pre>\n\n<p>I found it <a href="http://www.interact-sw.co.uk/iangblog/2006/06/03/pshfindstr" rel="noreferrer">here</a> which has a great indepth answer!</p>\n'}, {'answer_id': 14725, 'author': 'slipsec', 'author_id': 1635, 'author_profile': 'https://Stackoverflow.com/users/1635', 'pm_score': 0, 'selected': False, 'text': '<pre><code>if ($entry.EntryType -eq "Error")\n</code></pre>\n\n<p>Being Object Oriented, you want to test the property in question with one of the standard comparison operators you can find <a href="http://www.computerperformance.co.uk/powershell/powershell_syntax.htm#Operators_" rel="nofollow noreferrer">here</a>.</p>\n\n<p>I have a <a href="http://slipsec.blogspot.com/2008/04/monitoring-remote-event-logs-from.html" rel="nofollow noreferrer">PS script</a> watching logs remotely for me right now - some simple modification should make it work for you.</p>\n\n<p>edit: I suppose I should also add that is a cmdlet built for this already if you don\'t want to unroll the way I did.  Check out:</p>\n\n<pre><code>man Get-EventLog\nGet-EventLog -newest 5 -logname System -EntryType Error\n</code></pre>\n'}, {'answer_id': 14737, 'author': 'denis phillips', 'author_id': 748, 'author_profile': 'https://Stackoverflow.com/users/748', 'pm_score': 3, 'selected': False, 'text': '<p>For example, find all instances of "#include" in the c files in this directory and all sub-directories.</p>\n\n<pre><code>gci -r -i *.c | select-string "#include"\n</code></pre>\n\n<p>gci is an alias for get-childitem</p>\n'}, {'answer_id': 15032, 'author': 'Steven Murawski', 'author_id': 1233, 'author_profile': 'https://Stackoverflow.com/users/1233', 'pm_score': 2, 'selected': False, 'text': "<p>Just to expand on Monroecheeseman's answer.  gci is an alias for Get-ChildItem (which is the equivalent to dir or ls), the -r switch does a recursive search and -i means include.</p>\n\n<p>Piping the result of that query to select-string has it read each file and look for lines matching a regular expression (the provided one in this case is ERROR, but it can be any .NET regular expression). </p>\n\n<p>The result will be a collection of match objects, showing the line matching, the file, and and other related information.</p>\n"}, {'answer_id': 12324320, 'author': 'Chris Rudd', 'author_id': 1229736, 'author_profile': 'https://Stackoverflow.com/users/1229736', 'pm_score': 0, 'selected': False, 'text': '<p>On a related note, here\'s a search that will list all the files containing a particular regex search or string.  It could use some improvement so feel free to work on it.  Also if someone wanted to encapsulate it in a function that would be welcome.</p>\n\n<p>I\'m new here so if this should go in it\'s own topic just let me know.  I figured I\'d put it her since this looks mostly related.</p>\n\n<pre><code># Search in Files Script\n# ---- Set these before you begin ---- \n$FolderToSearch="C:\\" # UNC paths are ok, but remember you\'re mass reading file contents over the network\n$Search="Looking For This" # accepts regex format\n$IncludeSubfolders=$True #BUG: if this is set $False then $FileIncludeFilter must be "*" or you will always get 0 results\n$AllMatches=$False\n$FileIncludeFilter="*".split(",") # Restricting to specific file types is faster than excluding everything else\n$FileExcludeFilter="*.exe,*.dll,*.wav,*.mp3,*.gif,*.jpg,*.png,*.ghs,*.rar,*.iso,*.zip,*.vmdk,*.dat,*.pst,*.gho".split(",")\n\n# ---- Initialize ----\nif ($AllMatches -eq $True) {$SelectParam=@{AllMatches=$True}}\nelse {$SelectParam=@{List=$True}}\nif ($IncludeSubfolders -eq $True) {$RecurseParam=@{Recurse=$True}}\nelse {$RecurseParam=@{Recurse=$False}}\n\n# ---- Build File List ---- \n#$Files=Get-Content -Path="$env:userprofile\\Desktop\\FileList.txt" # For searching a manual list of files\nWrite-Host "Building file list..." -NoNewline\n$Files=Get-ChildItem -Include $FileIncludeFilter -Exclude $FileExcludeFilter -Path $FolderToSearch -ErrorAction silentlycontinue @RecurseParam|Where-Object{-not $_.psIsContainer} # @RecurseParam is basically -Recurse=[$True|$False]\n#$Files=$Files|Out-GridView -PassThru -Title \'Select the Files to Search\' # Manually choose files to search, requires powershell 3.0\nWrite-Host "Done"\n\n# ---- Begin Search ---- \nWrite-Host "Searching Files..."\n$Files|\n    Select-String $Search @SelectParam| #The @ instead of $ lets me pass the hastable as a list of parameters.  @SelectParam is either -List or -AllMatches\n    Tee-Object -Variable Results|\n    Select-Object Path\nWrite-Host "Search Complete"\n#$Results|Group-Object path|ForEach-Object{$path=$_.name; $matches=$_.group|%{[string]::join("`t", $_.Matches)}; "$path`t$matches"} # Show results including the matches separated by tabs (useful if using regex search)\n\n&lt;# Other Stuff\n    #-- Saving and restoring results\n    $Results|Export-Csv "$env:appdata\\SearchResults.txt" # $env:appdata can be replaced with any UNC path, this just seemed like a logical place to default to\n    $Results=Import-Csv "$env:appdata\\SearchResults.txt"\n\n    #-- alternate search patterns\n    $Search="(\\d[-|]{0,}){15,19}" #Rough CC Match\n#&gt;\n</code></pre>\n'}, {'answer_id': 21749061, 'author': 'deostroll', 'author_id': 145682, 'author_profile': 'https://Stackoverflow.com/users/145682', 'pm_score': 0, 'selected': False, 'text': '<p>This is not the best way to do this:</p>\n\n<pre><code>gci &lt;the_directory_path&gt; -filter *.csv | where { $_.OpenText().ReadToEnd().Contains("|") -eq $true }\n</code></pre>\n\n<p>This helped me find all csv files which had the <code>|</code> character in them.</p>\n'}, {'answer_id': 35832654, 'author': 'skataben', 'author_id': 873131, 'author_profile': 'https://Stackoverflow.com/users/873131', 'pm_score': 0, 'selected': False, 'text': '<p>PowerShell has basically precluded the need for <em>findstr.exe</em> as the previous answers demonstrate. Any of these answers should work fine.</p>\n\n<p>However, <strong>if you actually need to use <em>findstr.exe</em></strong> (as was my case) here is a PowerShell wrapper for it:</p>\n\n<p>Use the <code>-Verbose</code> option to output the <em>findstr</em> command line.</p>\n\n<hr>\n\n<pre><code>function Find-String\n{\n    [CmdletBinding(DefaultParameterSetName=\'Path\')]\n    param\n    (\n        [Parameter(Mandatory=$true, Position=0)]\n        [string]\n        $Pattern,\n\n        [Parameter(ParameterSetName=\'Path\', Mandatory=$false, Position=1, ValueFromPipeline=$true)]\n        [string[]]\n        $Path,\n\n        [Parameter(ParameterSetName=\'LiteralPath\', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]\n        [Alias(\'PSPath\')]\n        [string[]]\n        $LiteralPath,\n\n        [Parameter(Mandatory=$false)]\n        [switch]\n        $IgnoreCase,\n\n        [Parameter(Mandatory=$false)]\n        [switch]\n        $UseLiteral,\n\n        [Parameter(Mandatory=$false)]\n        [switch]\n        $Recurse,\n\n        [Parameter(Mandatory=$false)]\n        [switch]\n        $Force,\n\n        [Parameter(Mandatory=$false)]\n        [switch]\n        $AsCustomObject\n    )\n\n    begin\n    {\n        $value = $Pattern.Replace(\'\\\', \'\\\\\\\\\').Replace(\'"\', \'\\"\')\n\n        $findStrArgs = @(\n            \'/N\'\n            \'/O\'\n            @(\'/R\', \'/L\')[[bool]$UseLiteral]\n            "/c:$value"\n        )\n\n        if ($IgnoreCase)\n        {\n            $findStrArgs += \'/I\'\n        }\n\n        function GetCmdLine([array]$argList)\n        {\n            ($argList | foreach { @($_, "`"$_`"")[($_.Trim() -match \'\\s\')] }) -join \' \'\n        }\n    }\n\n    process\n    {\n        $PSBoundParameters[$PSCmdlet.ParameterSetName] | foreach {\n            try\n            {\n                $_ | Get-ChildItem -Recurse:$Recurse -Force:$Force -ErrorAction Stop | foreach {\n                    try\n                    {\n                        $file = $_\n                        $argList = $findStrArgs + $file.FullName\n\n                        Write-Verbose "findstr.exe $(GetCmdLine $argList)"\n\n                        findstr.exe $argList | foreach {\n                            if (-not $AsCustomObject)\n                            {\n                                return "${file}:$_"\n                            }\n\n                            $split = $_.Split(\':\', 3)\n\n                            [pscustomobject] @{\n                                File = $file\n                                Line = $split[0]\n                                Column = $split[1]\n                                Value = $split[2]\n                            }\n                        }\n                    }\n                    catch\n                    {\n                        Write-Error -ErrorRecord $_\n                    }\n                }\n            }\n            catch\n            {\n                Write-Error -ErrorRecord $_\n            }\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 63909531, 'author': 'Patrick Burwell', 'author_id': 10836810, 'author_profile': 'https://Stackoverflow.com/users/10836810', 'pm_score': 0, 'selected': False, 'text': '<p>FYI:\nIf you update to Powershell version 7 you can use grep...\nI know egrep is in powershell on Azure CLI...\nBut SS is there!\nAn old article here:  [https://devblogs.microsoft.com/powershell/select-string-and-grep/]</p>\n'}]
['https://Stackoverflow.com/questions/14708', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1351/']