# Probably Easy

**URL:** <https://forums.powershell.org/t/probably-easy/5098>\
**Category:** PowerShell Help\
**Created:** [October 26, 2015, 1:15am UTC](https://forums.powershell.org/t/probably-easy/5098 "2015-10-26T01:15:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cody-everingham](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@cody-everingham](https://forums.powershell.org/u/cody-everingham)\
**Post date:** [October 26, 2015, 1:15am UTC](https://forums.powershell.org/t/probably-easy/5098/1 "2015-10-26T01:15:59Z")

</div>

Basically I just want to see if the variable (in this case $roomnumber) matches any of the targets I specify (in this case 1,2 and 3). Below is what I tried, and it doesn’t work.

$roomnumber = 1  
if ($roomnumber -match ‘1’,‘2’,‘3’) {  
write-output “works”  
}

I know I could do the following:

$roomnumber = 1  
if ($roomnumber -eq ‘1’ -or $roomnumber -eq ‘2’ -or $roomnumber -eq ‘3’) {  
write-output “works”  
}

But I was hoping there would be any easy way to ask from a list like:

if ($roomnumber -eq 1,13,563,12,2) {

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [October 26, 2015, 1:25am UTC](https://forums.powershell.org/t/probably-easy/5098/2 "2015-10-26T01:25:10Z")

</div>

You could try using the -contains operator

$rooms = 1,13,563,12,2  
$roomnumber = 563

PS\> $rooms -contains $roomnumber  
True

PS\> $roomnumber = 127  
PS\> $rooms -contains $roomnumber  
False

---

<div class="post-metadata">

**Author:** ![csandfeld](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@csandfeld](https://forums.powershell.org/u/csandfeld)\
**Post date:** [October 26, 2015, 2:51am UTC](https://forums.powershell.org/t/probably-easy/5098/3 "2015-10-26T02:51:33Z")

</div>

… and if you prefer doing it the other way arround, you can also use the -in operation

```
C:\> $rooms = 1,13,563,12,2

C:\> $roomnumber = 563
C:\> $roomnumber -in $rooms
True

C:\> $roomnumber = 127
C:\> $roomnumber -in $rooms
False

C:\>
```

---

<div class="post-metadata">

**Author:** ![mike-eyler](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mike-eyler](https://forums.powershell.org/u/mike-eyler)\
**Post date:** [October 27, 2015, 4:00pm UTC](https://forums.powershell.org/t/probably-easy/5098/4 "2015-10-27T16:00:41Z")

</div>

Are these sequential or random numbers or both?  
Does the script do anything besides output true or false for a match?

---

<div class="post-metadata">

**Author:** ![cody-everingham](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@cody-everingham](https://forums.powershell.org/u/cody-everingham)\
**Post date:** [October 28, 2015, 12:39am UTC](https://forums.powershell.org/t/probably-easy/5098/5 "2015-10-28T00:39:02Z")

</div>

Christian Sandfeld, I like where you were going with your solution, but sadly I can’t use the in operator with Powershell 1.0. Is there an “old” way to achieve this?

---

<div class="post-metadata">

**Author:** ![tore-groneng](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tore-groneng/32/723_2.png) [@tore-groneng](https://forums.powershell.org/u/tore-groneng)\
**Post date:** [October 28, 2015, 12:50am UTC](https://forums.powershell.org/t/probably-easy/5098/6 "2015-10-28T00:50:48Z")

</div>

That is a tough one. I don’t think I have ever written any scripts for version 1. That is like 10 years old or something. That would put you on Windows Server 2008 or Windows Server 2003?

Please do a get-host or $host or $PSVersionTable in a console window and paste the result here.

If you are on version one, I highly recommend an upgrade.

---

<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:44pm UTC](https://forums.powershell.org/t/probably-easy/5098/7 "2024-05-16T20:44:34Z")

</div>

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


