title: How to fill an array efficiently in Powershell
body: <p>I want to fill up a dynamic array with the same integer value as fast as possible using Powershell.<br>
  The Measure-Command shows that it takes 7 seconds on my system to fill it up.<br>
  My current code (snipped) looks like:  </p>
  
  <pre><code>$myArray = @()
  $length = 16385
  for ($i=1;$i -le $length; $i++) {$myArray += 2}  
  </code></pre>
  
  <p><sup>(Full code can be seen on <a href="https://gist.github.com/anonymous/81160f837827ad44e35f" rel="nofollow noreferrer">gist.github.com</a> or on <a href="https://superuser.com/questions/307496/how-can-i-set-excel-to-always-import-all-columns-of-csv-files-as-text/527894#527894">superuser</a>)</sup>  </p>
  
  <p>Consider that <code>$length</code> can change. But for better understanding I chose a fixed length.</p>
  
  <p><strong>Q:</strong> How do I speed up this Powershell code?</p>