title: How can I turn a delimited string into a nested hashtable in PowerShell?
body: <p>I am struggling to find a neat way to turn a delimited string into a hashtable.  For example given the string:</p>
  
  <pre><code>UK_Kent_Margate
  </code></pre>
  
  <p>I want to turn this into a PowerShell HashTable that looks like this:</p>
  
  <pre><code>$result = @{
      UK = @{
          Kent = @{
              Margate = @{}
          }
      }
   }
  </code></pre>
  
  <p>So I can easily break the string into an array using a split on the '_' character but then I am struggling (read stuck!) with testing and declaring each of the nested hashes in the results hash.  I think I will need a recursive function which is no problem, but I cannot get my head around on how to test the right level in the results hash.</p>
  
  <p>As the application I am writing could have an arbitrary number of '_' and thus nests I need to come up with a slick way of doing this, and I cannot think of how to do it.</p>
  
  <p>Has anyone come across anything like this before and have any recommendations?</p>