How to initialize an array of custom objects

后端 未结 9 2483
粉色の甜心
粉色の甜心 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:30

    The simplest way to initialize an array

    Create array

    $array = @()
    

    Create your header

    $line = "" | select name,age,phone
    

    Fill the line

    $line.name = "Leandro"
    $line.age = "39"
    $line.phone = "555-555555"
    

    Add line to $array

    $array += $line
    

    Result

    $array
    
    name                                                     age                                                      phone
    ----                                                     ---                                                      -----
    Leandro                                                  39                                                       555-555555
    

提交回复
热议问题