title: powershell excel get first row(header) column count
body: <p>I'm trying to count the cell number of the first row (A1-D1) which is known as header and get that count as the counter.</p>
  
  <p>As all the while find most of them using <code>Usedrange</code> to count the columns:</p>
  
  <pre><code>$headercolcount=($worksheet.UsedRange.Columns).count 
  </code></pre>
  
  <p>But <code>UsedRange</code> will capture maximum count in the whole activesheet, which resulting not identical to the column count in first row if there is extra content data below the header.</p>
  
  <p>I only wish to grab just the first row:</p>
  
  <p>[<img src="https://i.stack.imgur.com/Q34dl.png" alt="Sample excel view">]</p>
  
  <p>Update:
  For clearer view, here is an example.
  As 1F &amp; 1G there are no value present, so the answer should be 5 as 1A-1E as it contains data. So how should I grab the 5 correctly?</p>
  
  <p>[<img src="https://i.stack.imgur.com/5WxjY.png" alt="enter image description here">]</p>