Chrissy LeMaire has a quick pair of one-liners for counting occurrences in Powershell:
I always forget how to do this, and Aleksandar Nikolić posted a really beautiful answer on Powershell.com
For a file:
-split (Get-Content .\test.txt | Out-String) | Where-Object { $_ -eq "test" } | Measure-Object | Select-Object -exp count
That was easy. Check out the article to see how to do this with a string.