I\'m new to powershell and have no experience with .net. I have a script that use
(get-content | select-string -pattern -allmatches).matches | measure-object
You can use ToCharArray
and where
to find the matches. For example, to count the number of "e" in the file you can say:
$file = get-item ''
$reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $file
[int]$count = 0
while ( $read = $reader.ReadLine() ) {
$matches = ($read.ToCharArray() | where {$_ -eq 'e'}).Count
$count = $count + $matches
}