title: How to initialize a large, multi-dimensional array in Powershell?
body: <p>Regarding this topic, I've so far found two questions here which relate to my question, but not fully. I have found how to initialize a large array, <a href="https://stackoverflow.com/questions/43083051/creating-an-array-with-large-initial-size-in-powershell/43083117">here</a>. Additionally, I've found how to declare a multi-dimensional array, <a href="https://stackoverflow.com/questions/9397137/powershell-multidimensional-arrays">here</a>. I've yet to find a solution which covers how to both declare AND initialize a multi-dimensional array. In my case, I need an array[10][10] with all elements initialized to zero. Currently I do this as follows:</p>
  <pre><code>$array = @(
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  )
  </code></pre>
  <p>This, of course, is completely un-scalable. From the first question, I found that <code>$arr = @(0) * 10000</code> works for regular arrays, so I tried to use <code>$array = @(@(0) * 10) * 10</code>, and while this runs just fine, trying to access any element of this array gives me a 'Cannot modify because element is null' error.</p>
  <p>To clarify, this code:</p>
  <pre><code>$array = @(
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      @(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  )
  Write-Host &quot;$($null -eq $array[1][5])&quot;
  </code></pre>
  <p>returns False, where as this code:</p>
  <pre><code>$array = @(@(0) * 10) * 10
  Write-Host &quot;$($null -eq $array[1][5])&quot;
  </code></pre>
  <p>returns True.</p>
  <p>What is the definitive, correct, scalable way to declare and initialize an array with N-dimensions?</p>