title: PowerShell: How to increment counter when condition is satisfied
body: <p>My requirement is to go through each directory and sub-directory and find a character after the third dash(-) in a file name and if it is an "A", increment the counter and at the end of the process, write to the host total number of files that met the required condition. How would I do that?</p>
  
  <p>Here is my script:</p>
  
  <pre><code>$counter = 0
  dir .\ -Recurse | % {
      if (($_.Name.Split("-")[3] -notmatch "[^C]")) {
          $counter++
          write-Host $_.Name.Split("-")[3]
          $counter
      }
  }
  </code></pre>