-contains

Contains is a conditional operator that will test for the existence of one item in a collection, array or hashtable.

Syntax
 expression -contains expression

Contains is an exact (but case-insensitive) match and will ignore wildcards.

To examine the contents of values within a string, either use a wildcard -match or -split the string into an array.

This operator returns True or False.

Examples

PS C:\> $demoArray = 'alpha', 'beta', 'New York'
PS C:\> $demoArray -contains "Alpha"
True
PS C:\> $demoArray -contains 'New'
False
PS C:\> $demoArray -contains 'New york'
True

PS C:\> $string = 'alpha, beta, California'
PS C:\> $string -contains 'alpha'
False
PS C:\> $string -split ',' -contains 'alpha'
True

"Do I contradict myself? Very well, then I contradict myself, I am large, I contain multitudes" ~ Walt Whitman

Related PowerShell Cmdlets

-ccontains - Case sensitive -contains
-eq - Equality comparison Operator.
Syntax - Comparison Operators

(追記) (追記ここまで)
Copyright © 1999-2026 SS64.com
Some rights reserved

AltStyle によって変換されたページ (->オリジナル) /