title: Creating a reference to a hash table element
body: <p>So, I'm trying to create a tree-type variable that I could use for data navigation. I've ran into an issue while trying to use reference variables on hash tables in PowerShell. Consider the following code:</p>
  
  <pre><code>$Tree = @{ TextValue = "main"; Children = @() }
  $Item = @{ TextValue = "sub"; Children = @() }
  $Pointer = [ref] $Tree.Children
  $Pointer.Value += $Item
  $Tree
  </code></pre>
  
  <p>When checking reference variable <code>$Pointer</code>, it shows appropriate values, but main variable <code>$Tree</code> is not affected. Is there no way to create references to a hash table element in PowerShell, and I'll have to switch to a 2-dimensional array?</p>
  
  <p>Edit with more info:</p>
  
  <p>I've accepted Mathias' answer, as using <code>List</code> looks like exactly what I need, but there's a little more clarity needed on how arrays and references interact. Try this code:</p>
  
  <pre><code>$Tree1 = @()
  $Pointer = $Tree1
  $Pointer += 1
  Write-Host "tree1 is " $Tree1
  $Tree2 = @()
  $Pointer = [ref] $Tree2
  $Pointer.Value += 1
  Write-Host "tree2 is " $Tree2
  </code></pre>
  
  <p>As you can see from the output, it is possible to get a reference to an array and then modify the size of the array via that reference. I thought it would also work if an array is an element of another array or a hash table, but it does not. PowerShell seems to handle those differently.</p>