I am trying to create a powershell script which looks through all files and folders under a given directory it then changes all instances of a given word in .properties file
The simplest way to check that file contains the word
If we are looking at Get-Content
result we find string System.Array. So, we can do like in System.Linq in .NET:
content.Any(s => s.Contains(wordToFind));
In PowerShell it looks like:
Get-Content $filePath `
| %{ $res = $false } `
{ $res = $res -or $_.Contains($wordToFind) } `
{ return $res }
As a result, we can aggregate it in cmdlet with params of file path and containing word and use it. And one more: we can use Regex with -match
instead of Contains
, so it will be more flexible.