I've been banging my head against a wall for hours now and am looking for some help. To simplify my issue, I have two arrays, one which contains wildcards, and the other which makes use of those wildcards:
$WildCardArray = @("RED-*.htm", "*.yellow", "BLUE!.txt", "*.green", "*.purple")
$SpelledOutArray = @("RED-123.htm", "456.yellow", "BLUE!.txt", "789.green", "purple.102", "orange.abc")
I cannot get PowerShell to recognize that these match.
My end goal is to have an output that tells me that purple.102 and orange.abc are not in $WildCardArray.
Seems super simple! Some of the things I've tried:
$WildCardArray = @("RED-*.htm", "*.yellow", "BLUE!.txt", "*.green", "*.purple")
$SpelledOutArray = @("RED-123.htm", "456.yellow", "BLUE!.txt", "789.green", "purple.102", "orange.abc")
foreach($Item in $SpelledOutArray)
{
$item | where {$wildcardarray -contains $item}
}
I get BLUE!.txt as a result because it's my control with no wildcards. If I change that to -notcontains, I get all of the results returned except BLUE. I've tried contains, match, equals, like and all of their opposites, compare-object, and nothing works. I get no errors, I just do not get the expected results
I tried replacing "*" with [a-zA-Z] and other combinations, but it replaces it literally, and not as a wildcard. I'm not sure what I'm doing wrong.... PSVersion 5.1 Win 10
Does anybody know the logic behind WHY like/match/contains doesn't work, and what I can do make it work? It doesn't have to be pretty, it just needs to work
-containslooks for exact match, and I'm pretty sure it threats*as a character without any special meaning$WildCardArray | ForEach-Object {$Wildcard = $_ ; $SpelledOutArray | Where-Object {$_ -like $WildCard}}