24/7/365 Support

Find Items in an Array That Match a Value

Problem

You have an array and want to find all elements that match a given item or term— either exactly, by pattern, or by regular expression.

Solution

To find all elements that match an item, use the –eq, like, and –match comparison operators:

PS >$array = "Item 1","Item 2","Item 3","Item 1","Item 12" PS >$array eq "Item 1" Item 1 Item 1 PS >$array like "*1*" Item 1 Item 1 Item 12 PS >$array match "Item .." Item 12

Discussion

The eq, like, and match operators are useful ways to find elements in a collection that match your given term. The –eq operator returns all elements that are equal to your term, the –like operator returns all elements that match the wildcard given in your pattern, and the –match operator returns all elements that match the regular expression given in your pattern.

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say