# Foreach value

**URL:** <https://forums.powershell.org/t/foreach-value/12486>\
**Category:** PowerShell Help\
**Created:** [May 1, 2019, 4:15pm UTC](https://forums.powershell.org/t/foreach-value/12486 "2019-05-01T16:15:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![incognitotom](https://avatars.discourse-cdn.com/v4/letter/i/e495f1/32.png) [@incognitotom](https://forums.powershell.org/u/incognitotom)\
**Post date:** [May 1, 2019, 4:15pm UTC](https://forums.powershell.org/t/foreach-value/12486/1 "2019-05-01T16:15:32Z")

</div>

Hi,

I’m trying to build some pipelines in Azure Devops, and need a way to loop through a hashtable or PSObject and create DevOps variables that can be passed through the pipeline.

for example:

```
$myVariables = @{
  'ID' = 'kf5jkdfgjld'
  'Acc' = '4489933'
}

# now need to take those values and pass to this cmdlet
```

```
foreach ($Item in $myVariables){
      Write-Host "##vso[task.setvariable variable=$MyVariable.Key]$MyVariable.Value"
}
```
The idea the the hashtable could contain loads of values and i dont want create a line for everyone.

Hope that makes senes.

Thanks

---

<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:** [May 1, 2019, 7:01pm UTC](https://forums.powershell.org/t/foreach-value/12486/2 "2019-05-01T19:01:39Z")

</div>

```
$myVariables = @{
  'ID' = 'kf5jkdfgjld'
  'Acc' = '4489933'
}
foreach ($Item in $myVariables){
    foreach ($Key in $Item.Keys) {
          "##vso[task.setvariable variable=$Key]$($Item.$Key)"
    }
}
```

---

<div class="post-metadata">

**Author:** ![lovelyseraph](https://avatars.discourse-cdn.com/v4/letter/l/7cd45c/32.png) [@lovelyseraph](https://forums.powershell.org/u/lovelyseraph)\
**Post date:** [May 3, 2019, 12:51am UTC](https://forums.powershell.org/t/foreach-value/12486/3 "2019-05-03T00:51:33Z")

</div>

```
[Array]$myVariables = 'ID,kf5jkdfgjld'| ConvertFrom-CSV -Header "Name","Value" -Delimiter ","
$myVariables += 'Acc,4489933'| ConvertFrom-CSV -Header "Name","Value" -Delimiter ","

foreach ($Item in $myVariables){
Write-Host ($Item.Name +" IS "+$Item.Value)
}
```

---

<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:32pm UTC](https://forums.powershell.org/t/foreach-value/12486/4 "2024-05-16T20:32:51Z")

</div>

Closed on May 16, 2024, 8:32pm UTC


