Nested PowerShell-CustomObjects (JSON)

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche

How do I create a nested PowerShell custom object to store layers (nested) of information?
Use a hashtable with the PSCustomObject type accelerator, and specify PSCustomObject as the value to the Property Name (Key)


$JSON = [PSCustomObject]@{
    Property1NameLayer1 = [PSCustomObject]@{ 
        Property2NameLayer2 = [PSCustomObject]@{
            Property3NameLayer3 = 'Property3Value'
        }
        Property4NameLayer2= 'Property2Value'
        Property5NameLayer2= 'Property3Value'
    }
} | ConvertTo-Json