Simple PowerShell snippet to search file or array for content.

April 22, 2015

Since I play these days a lot with PowerShell I need from time to time some simple functionality. Sometimes dead simple. Like today , snippet to search file content or array of data if you will and return true/false if text is present in it.

function File-Contains-Row {
    Param([array]$fileContent, [string]$searchedString)

    Process {
    #is there any string we search for in any of the rows?
    [array]$resArray = $fileContent | where { $_ | Select-String –caseSensitive -Pattern $searchedString }

    if ($resArray.Count -eq 0) {
        return $false
    } else {
        return $true

As a project, you can find it here :

.ps1 file is here :

Hope this helps.

Profile picture

Written by Dušan Roštár - the "mr edge case" guy
my twitter : rostacik, my linkedin : rostar, drop me an email : here