PowerShell: Test If Collection Contains a Value

By Xah Lee. Date: . Last updated: .

Operator names are case-insensitive.

-contains operator

-contains
collection contains a value. case-insensitive.
$x = 1,2,3
$x -contains 3
# True
$x = "A","B"
$x -contains "a"
# True

$x = "A","B"
$x -icontains "a"
# True

$x = "A","B"
$x -ccontains "a"
# False
-icontains
same as -contains.
-ccontains
case-sensitive version of -contains.
-notcontains
negation of -contains
-inotcontains
same as -notcontains
-cnotcontains
case-sensitive version of -notcontains

-in operator

-in
value is in a collection. The -in operator is like -contains, but the operands are in reverse order.
-notin
value is not in a collection
$x = 1,2,3
3 -in $x
# True
-iin
case-insensitive, same as -in
-inotin
case-insensitive version of -notin
-cin
case-sensitive, same as -in
-cnotin
case-sensitive version of -notin

PowerShell: Array

PowerShell Operators