Creating an array of multidimensional hash tables in Powershell

I was wondering if there is a shorter way to create a multidimensional hash table array in powershell. I was able to successfully create them using a pair of such strings.

$arr = @{}
$arr["David"] = @{}
$arr["David"]["TSHIRTS"] = @{}
$arr["David"]["TSHIRTS"]["SIZE"] = "M"

That said, I was wondering if there is a way to cut this down to something like this ...

$new_arr["Level1"]["Level2"]["Level3"] = "Test" 

Where he will create a new level, if he does not exist yet. Thank!

+4
source share
1 answer

You need to specify / define sub-levels, otherwise the interpreter does not know what type it works with (array, single node, object, etc.)

$arr = @{
    David = @{
        TSHIRTS = @{
            SIZE = 'M'
        }
    }
}
+8
source

Source: https://habr.com/ru/post/1683924/


All Articles