title: In PowerShell, how can I exclude commented lines even though they include the pattern I am seeking to include?
body: <p>I am using a PowerShell script to read a file to get an assembly version, which I use to as part of an output file name.  However, the file I am reading also contains comments ("//"), which I would like to ignore.</p>
  
  <p>Here are two lines from my input file.  The first is a comment line to be ignored, the second is a line with the desired value:</p>
  
  <pre><code>// [assembly: AssemblyVersion("1.0.*")]
  [assembly: AssemblyVersion("1.0.0.0")]
  </code></pre>
  
  <p>Here's my current script:</p>
  
  <pre><code> param (
      [string]$path
     ,[string]$file = "AssemblyInfo.cs"
     ,[string]$projectName)
  
  # Search for the AssemblyVersion to be appended to the filename
  $pattern = '\[assembly: AssemblyVersion\("(.*)"\)\]'
  (Get-Content $path\$file) | ForEach-Object{
      if($_ -match $pattern){
          $fileVersion = [version]$matches[1]
      }
  } 
  Write-Host $projectName-$fileVersion
  </code></pre>
  
  <p>The current pattern matches on <em>both</em> lines of input.  Because the comment doesn't have a valid version, it produces an error:</p>
  
  <pre><code>Cannot convert value "1.0.*" to type "System.Version". 
  Error: "Input string was not in a correct format."
  At C:\Scripts\Powershell\Get-FileName.ps1:10 char:36
  +         $fileVersion = [version]$matches[ &lt;&lt;&lt;&lt; 1]
  + CategoryInfo          : NotSpecified: (:) [], RuntimeException
  + FullyQualifiedErrorId : RuntimeException
  </code></pre>
  
  <p>How can I modify the $pattern value or the "if($_ -match $pattern)" in order to ignore commented lines?</p>