Create variable with mutiples tables

Steven N 96 Reputation points
2020-08-21T15:26:08.487+00:00

Hello,

I do not know how to phrase that question correctly so I will try with example.

Here is the JSON example of what I'd like to recreate in PowerShell format:

[
    {
        id : "001",
        name : "apple",
        category : "fruit",
        color : "red"
    }, 
...
]

I am not sure if it's possible to do the same in PowerShell.

Thanks,
Steven

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2020-08-21T18:33:46.357+00:00

    I don't think you found the correct answer . . . not if your original question had the structure you're after. Try this instead:

    $CLIENTTABLE1 = @(
        [ordered]@{
                    name = "HELLO"
                    ipaddress = "1.1.1.1"
                  },
        [ordered]@{
                    name = "WORLD"
                    ipaddress = "2.2.2.2"
                  }
    )
    $CLIENTTABLE1 | ConvertTo-Json
    

    That produces this:

    [
        {
            "name":  "HELLO",
            "ipaddress":  "1.1.1.1"
        },
        {
            "name":  "WORLD",
            "ipaddress":  "2.2.2.2"
        }
    ]
    
    0 comments No comments