How to initialize an array of custom objects

后端 未结 9 2494
粉色の甜心
粉色の甜心 2020-12-13 23:44

First, as this leads to my question, I\'ll start by noting that I\'ve worked with XML a fair bit in PowerShell, and like how I can read data from XML files, quickly, into ar

9条回答
  •  孤街浪徒
    2020-12-14 00:36

    Here is a concise way to initialize an array of custom objects in PowerShell.

    > $body = @( @{ Prop1="1"; Prop2="2"; Prop3="3" }, @{ Prop1="1"; Prop2="2"; Prop3="3" } )
    > $body
    
    Name                           Value
    ----                           -----
    Prop2                          2
    Prop1                          1
    Prop3                          3
    Prop2                          2
    Prop1                          1
    Prop3                          3  
    

提交回复
热议问题