I have an array of objects and I want to pull out a set where a property matches any entry in an array of strings: with wildcards. I couldn't find a solution anywhere (or even others having the same issue), so here's the thought process I went through.

To start with, I explored -in:

$items = @("ANACONDA", "BACON", "CAT", "DOG")

$items | Where-Object { $_ -in "CAT" }
# CAT
$search = @("CAT", "DOG")
$items | Where-Object { $_ -in $search }
# CAT
# DOG
$items | Where-Object { $_ -in "CA*" }
#

-in works with arrays, but it doesn't work with wildcards. So I tried -like:

$search = @("C*", "D*")

$items | Where-Object { $_ -like "C*" }
# CAT
$items | Where-Object { $_ -like $search }
#

-like works with wildcards, but doesn't work with arrays. So here's the solution I came up with.

Expand the wildcards into a second string array with the full matching names from the items we wanted to match against. There's a bit of convolution to make sure we end up with a simple unique string array - without it you can end up with arrays within arrays.

$expanded = $search |
    Select-Object @{ Name="ExpandedItem"; Expression={ $items -Like $_ }} |
    Select-Object -ExpandProperty ExpandedItem -Unique
# CAT
# DOG

For the example that's far enough, but for me remember I was looking for objects with certain properties. With this expanded non-wildcard search list, I could now fall back on using a simple -in:

$items | Where-Object { $_ -in $expanded }
# CAT
# DOG

I hope someone else finds this useful. If you know a better method please let me know.