Use the -contains operator:

Copy$InputArray -contains $UserInput

With more recent PowerShell versions (v3 and above) you could also use the -in operator, which feels more natural to many people:

Copy$UserInput -in $InputArray

Beware, though, that either of them does a linear search on the reference array ($InputArray). It doesn't hurt if your array is small and you're not doing a lot of comparisons, but if performance is an issue using hashtable lookups would be a better approach:

Copy$validInputs = @{
    'a' = $true
    'e' = $true
    'i' = $true
    'o' = $true
    'u' = $true
    '1' = $true
    '2' = $true
    '3' = $true
    '4' = $true
    '5' = $true
}

$validInputs.ContainsKey($UserInput)
Answer from Ansgar Wiechers on Stack Overflow
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › powertip: does powershell array contain a value?
PowerTip: Does PowerShell Array Contain a Value? - Scripting Blog [archived]
June 8, 2014 - Use the Contains method from an array. In the following example, the $array variable contains an array. The next line checks to see if the number 2 is in the array. It is, and the method returns True.
🌐
LazyAdmin
lazyadmin.nl › home › powershell array contains explained
PowerShell Array Contains Explained — LazyAdmin
October 16, 2024 - To check if a value exists in an array, we can use the -Contains operator in PowerShell. This will return return true if the value exists.
🌐
IDERA
idera.com › home › determine if array contains value – using wildcards
Determine if Array Contains Value – Using Wildcards | IDERA
April 21, 2025 - If you’d like to know whether an array contains a given element, PowerShell provides the –contains operator.
🌐
DEV Community
dev.to › taijidude › check-if-an-array-contains-a-certain-string-4ao
Check if an array contains a certain string - DEV Community
November 13, 2022 - Last week I was searching through a huge array of strings by hand/eye. I was looking for certain active directory groups. I quickly realized how stupid this was and researched ("googled" ;-)) how to check if a powershell array contains a string.
🌐
Reddit
reddit.com › r/powershell › how do i check if an array of arrays contains an array?
r/PowerShell on Reddit: How do I check if an array of arrays contains an array?
August 24, 2023 -

After having initialised an array of arrays, I wanted to check whether if this array of arrays contained a specific array or not. So, I tried this:

$array = (1, 2), (3, 4), (5, 6)
($array -contains (1, 2))

Unfortunately, that returned "False", for some reason. I then tried to use a foreach loop to solve this, with this setup:

$array = (1, 2), (3, 4), (5, 6)
foreach ($item in $array)
{
($item -eq (1,2))
}

but the comparisson of the two arrays seems to return absolutely nothing, and I don't get why. However, doing something like this:

$array = (1, 2), (3, 4), (5, 6)
($array -contains $array[0])

works mighty fine, despite of $array[0] and (1, 2) being essentially the same in function.

Please provide me with some enlightenment about this issue.

Find elsewhere
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › using the powershell contains operator
Using the PowerShell Contains Operator - Scripting Blog [archived]
December 13, 2013 - This following technique illustrates an array of three values that is created and stored in the variable $noun. The Contains operator is then used to see if the array contains “hairy-nosed wombat”. Because the $noun variable does not have an array element that is equal to the string “hairy-nosed wombat,” the Contains operator returns False.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › deep-dives › everything-about-arrays
Everything you wanted to know about arrays - PowerShell | Microsoft Learn
PS> $data = @('red','green','blue') PS> $data -contains 'green' True · When you have a single value that you would like to verify matches one of several values, you can use the -in operator. The value would be on the left and the array on the right-hand side of the operator.
🌐
Spiceworks
community.spiceworks.com › programming & development
Powershell match an item in an array - Programming & Development - Spiceworks Community
February 3, 2017 - There have been many times where I wanted select items that match one or more items in a list/array. Is this possible? I can’t seem to find any documentation on if what I am trying to achieve can be done as I expect. Example: $ToMatch = @('String1','String2','String3') Get-ADComputer -Filter * | ?{$_.Name -match $ToMatch}
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to use powershell “contains” – a quick guide!
How to use PowerShell "Contains" - A Quick Guide! - SharePoint Diary
August 8, 2025 - The Contains method in PowerShell helps you see if a specified string or character exists within a string. The PowerShell operator -Contains lets you check if a collection of objects, such as an array, contains a specific object or value.
🌐
PowerShell Forums
forums.powershell.org › powershell help
-contains vs .contains() - PowerShell Help - PowerShell Forums
December 2, 2014 - This may be a easy question, but I am a bit confused. I have a script that I am using in a point-of-sale environment. 700 PCs. Each named consistently, like this - POS_A_[NUMBER] for each location. For example, POS_A_101, POS_B_101, POS_A_102, POS_B_102, etc…all the way to 700.
🌐
Netwrix
netwrix.com › home › resources › blog › how to use powershell arrays
How to Use PowerShell Arrays | Netwrix
December 13, 2024 - IntroductionCreating an Array of ObjectsCreating an Array with Just One ElementCreating an Empty ArrayCreating a Strongly Typed ArrayCreating a Multidimensional Array (Matrix)Comparing, Grouping, Selecting and Sorting ArraysLooping through an ArrayUsing a PipelineAdding to an ArrayCreating an ArrayListRemoving an Item from an ArrayClearing an ArrayPrinting an ArrayFiltering an ArrayChecking the Length of an ArrayChecking Whether an Array Contains a Particular ValueAccessing Items using the Array IndexUsing the Join Operator and the Split OperatorUsing the Replace OperatorSlicing an ArrayReversing an ArrayConclusionNow Netwrix Can Help
🌐
PowerShell Forums
forums.powershell.org › powershell help
PowerShell -Contains comparission against an array of string - PowerShell Help - PowerShell Forums
May 23, 2024 - Greetings, I am trying the following PS but it is not working. In other words, it is not returning any value to list $Offices = @(‘India’,‘Guatemala’) $List = Get-MsolUser -All | Where-Object {$.Office -Contains $Offices} | Select UserPrincipalName But if I try with just one value, ...
🌐
PowerShell Forums
forums.powershell.org › powershell help
Check if 1 value of one array inside another array array exists inside the master Array - PowerShell Help - PowerShell Forums
May 20, 2022 - I have a master array ($proccessarray) that has other arrays inside it ($proccessarray[0] and $proccessarray[1]). There are some situations where I would like to check if 1 of the values of the one of the sub-arrays (‘proccess1’) that is inside the master array, but a simple comparison operator fails: $ProcessList =@('proccess1','process2','process3','proccess4') $proccessarray =@() $proccessarray += @(,$ProcessList[0..1]) $proccessarray += @(,$ProcessList[2..3]) $proccessarray[0] $proccessa...
🌐
Varonis
varonis.com › blog › powershell-array
PowerShell Array Guide: How to Use and Create
June 9, 2022 - You can use it to check if an array contains a particular string, and it will output a Boolean value. For instance: PS> $data = @('red','green','blue') PS> $data -contains 'green' True · There are two operators for checking for equality in PowerShell: -eq and -ne.
🌐
Sysadmin Central
sysadmin-central.com › 2021 › 11 › 04 › powershell-how-to-check-if-string-contains-any-value-in-array
PowerShell – How to Check if String Contains Any Value in Array
October 4, 2022 - # Set the variables $description = "Red fox jumping over fences" $searchArray = @("fox", "red", "blue") # Simple function to check if a string contains any one of a set of terms to search for # Returns True if found or False otherwise function containsArrayValue { param ( [Parameter(Mandatory=$True)] [string]$description, [Parameter(Mandatory=$True)] [array]$searchTerms ) foreach($searchTerm in $searchTerms) { if($description -like "*$($searchTerm)*") { return $true; } } return $false; } # Call the function containsArrayValue $description $searchArray ... Try Cartel Empire today. A completely
🌐
Hosting Ultra So
hostingultraso.com › help › windows › determine-whether-array-contains-item
Determine Whether an Array Contains an Item | Windows PowerShell, Windows Server | HostingUltraso.com
Solution To determine whether a list contains a specific item, use the –contains operator: PS >"Hello","World" contains "Hello" True PS >"Hello","World" contains "There" False Discussion The –contains operator is a useful way to quickly determine whether a list contains a specific element.
🌐
Computer Performance
computerperformance.co.uk › home › powershell
PowerShell Basics -Contains, -CContains & -NotContains | Code Examples
January 21, 2019 - # PowerShell -Contains Operator Clear-Host $ArraySimple =@("House","Flats","Bungalow") $ArraySimple -Contains "Flat" # Result PS> False