title: Powershell, Counting string ocurrences in a text file
body: <p>I got a text file with the following layout, </p>
  
  <pre><code>Lorem Ipsum Lorem Ipsum Ipsum user:john
  Lorem Ipsum user:peter
  Lorem Ipsum Lorem Ipsum user:george
  Lorem Ipsum user:john
  Lorem Ipsum  vLorem Ipsum user:george
  Lorem Ipsum user:john
  </code></pre>
  
  <p>I must develop a script on Powershell V2 to count the occurrences and build a CSV with the following content,</p>
  
  <pre><code>john,3
  george,2
  peter,1
  </code></pre>
  
  <p>I was planning to loop thru the file saving each user in an array and then use get-content and a pattern to count the ocurrences, for example:</p>
  
  <pre><code>#assumming i was able to fill the array in some way :)
  $users =@('john','peter', 'george')
  for each ($user in $users)
  {
       $count = get-content .\myfile.txt | select-string -pattern "user:$user"
       write-host $count
  }
  #save the CSV
  </code></pre>
  
  <p>Does it makes sense? I'm ear-opened to your hints and tips. Knowing the power of Powershell I'm pretty user there is a better approach. Thanks!</p>