# How to add values to an array ...

**URL:** https://forums.powershell.org/t/how-to-add-values-to-an-array/8421
**Category:** PowerShell Help
**Created:** [April 12, 2017, 3:18am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421 "2017-04-12T03:18:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jean-marc](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jean-marc](https://forums.powershell.org/u/jean-marc)
#### Post date: [April 12, 2017, 3:18am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/1 "2017-04-12T03:18:13Z")

</div>

Hello world!

I’m completely newbie in Powershell and i need your help …  
I created 3 variables containing values separated by “;” :

$process = processname  
$Sresult = Sdata1;Sdata2;Sdata3;Sdata4;Sdata5 …  
$Iresult = Idata1;Idata2;Idata3;Idata4;Idata5 …

I would like to have an array or hash table like this (i don’t know what is the best solution) :

Process Sresult Iresult  
processname Sdata1 Idata1  
processname Sdata2 Idata2

and so on … at the end of course a small CSV output is planned. 🙂 …  
Thanks !

---

<div class="post-metadata">

### Author: ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)
#### Post date: [April 12, 2017, 4:18am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/2 "2017-04-12T04:18:43Z")

</div>

It might be helpful to know how you created this variables. It might be easier to create what you’re looking for directly in the process of getting the information than stitching it together afterwards. (sorry for my poor english)

---

<div class="post-metadata">

### Author: ![jean-marc](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jean-marc](https://forums.powershell.org/u/jean-marc)
#### Post date: [April 12, 2017, 6:19am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/3 "2017-04-12T06:19:44Z")

</div>

Hi Olaf

I retrieve these values from a complex xml-like file with several tags with a regex … these tags don’t have any ID …  
e.g. :

suppliers  
COM-09 To perform Operative Planning

inputs

Validated Operative Plan (full view & Cascaded)

I use this “really-dirty” foreach loop to parse all the lines :

```
# Retrieve the Suppliers
" ****************Suppliers**************************"
$pattern = "(?:)(.*)(?:)"
foreach ($suppliers in $XmlDocument.metadata.entry.map.entry.map.entry)
   {
    if ($suppliers.string -eq "suppliers")
      {
      $result = [Regex]::Match($suppliers.string, $pattern)
      $Sresult = $Sresult += $result.Value.replace('','').replace('','')
      $Sresult = $Sresult -replace "&","&"
      $Sresult = $Sresult + ";"
      }
    if ($suppliers.string -eq "inputs")
      {
      $result = [Regex]::Match($suppliers.string, $pattern)
      $Iresult = $Iresult += $result.Value.replace('','').replace('','')
      $Iresult = $Iresult -replace "&","&"
      $Iresult = $Iresult + ";"
    }
  }
```

---

<div class="post-metadata">

### Author: ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)
#### Post date: [April 12, 2017, 6:25am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/4 "2017-04-12T06:25:05Z")

</div>

```
#region Input
$Process = 'one','two','three'
$Color = 'green','blue','yellow'
$Memory = 2,4,8
#endregion

#region Process
# Put them in a Powershell Object:
$myOutput = 0..2 | foreach {
    [PSCustomObject]@{
        Process = $Process[$_]
        Color = $Color[$_]
        Memory = $Memory[$_]
    }
}
#endregion

#region Output
$myOutput | Format-Table -AutoSize # output to console
$myOutput | Out-GridView # output to ISE gridview
$myOutput | Export-Csv .\mystuff.csv -NoTypeInformation # dump to CSV
#endregion
```

---

<div class="post-metadata">

### Author: ![jean-marc](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jean-marc](https://forums.powershell.org/u/jean-marc)
#### Post date: [April 12, 2017, 6:41am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/5 "2017-04-12T06:41:30Z")

</div>

Works like a charm !

thanks you so much !

---

<div class="post-metadata">

### Author: ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)
#### Post date: [April 12, 2017, 6:42am UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/6 "2017-04-12T06:42:21Z")

</div>

For more information on arrays [see this article](https://superwidgets.wordpress.com/2014/08/23/working-with-powershell-arrays/)…

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/how-to-add-values-to-an-array/8421/7 "2024-05-16T20:38:58Z")

</div>


