Problem
You want to determine whether an array or list contains a specific item.
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. To search a list for items that instead match a pattern, use the –match or –like operators.
If you need dedicated infrastructure for checking whether arrays contain specific items, consider a Netherlands Dedicated Server for greater control over PowerShell scripting, data processing, automation, system administration, and Windows-based application workloads.
Help Category