# How to query an array for value

**URL:** <https://forums.powershell.org/t/how-to-query-an-array-for-value/23025>\
**Category:** PowerShell Help\
**Created:** [October 21, 2023, 9:10pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025 "2023-10-21T21:10:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://forums.powershell.org/u/Joey)\
**Post date:** [October 21, 2023, 9:10pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/1 "2023-10-21T21:10:46Z")

</div>

Hi,

I have a powershell array with the following contents (where name has unique values):

```
Name|Val1|Val2
Mary |25 |32 
Joe |38 |21 
Anne |38 |17

```

* * *

I would like to query the array with a query that would return val2 (17) for the row that has a value of Anne for Name.

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [October 21, 2023, 9:26pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/2 "2023-10-21T21:26:27Z")

</div>

Hi, welcome to the forum 👋

What have you tried so far?

If it’s an array with key/value pairs, then `Where-Object` will do the trick.

---

<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:** [October 21, 2023, 9:44pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/3 "2023-10-21T21:44:18Z")

</div>

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you potentially wasting their time.

Thanks

> <https://stackoverflow.com/questions/77337790/how-to-search-for-a-value-in-an-array-row-in-powershell>

---

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://forums.powershell.org/u/Joey)\
**Post date:** [October 21, 2023, 11:19pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/4 "2023-10-21T23:19:33Z")

</div>

I found the answer:

$array.where {$\_.name -eq ‘Anne’ }.val2

---

<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:** [October 21, 2023, 11:46pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/5 "2023-10-21T23:46:01Z")

</div>

Did you actually read the helpful comments on StackOverflow? 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [October 22, 2023, 1:19am UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/6 "2023-10-22T01:19:35Z")

</div>

OP obviously read Michael’s comment but proceeds to proclaim they _found_ the answer.

---

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://forums.powershell.org/u/Joey)\
**Post date:** [October 22, 2023, 3:04pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/7 "2023-10-22T15:04:33Z")

</div>

Not until right now.

---

<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:** [October 23, 2023, 1:08pm UTC](https://forums.powershell.org/t/how-to-query-an-array-for-value/23025/8 "2023-10-23T13:08:51Z")

</div>

Archived on October 23, 2023, 1:08pm UTC


