PowerShell - How to check a string to see if it contains another string with wildcard?
With wildcards you want to use -like
operator instead of -match
because the latter requires a regular expression. Example:
$files = @("MyApp.Tests.dll","MyApp.Tests.pdb","MyApp.dll")$excludeTypes = @("*.Tests.dll","*.Tests.pdb")foreach ($file in $files) { foreach ($type in $excludeTypes) { if ($file -like $type) { Write-Host ("Match found: {0} matches {1}" -f $file, $type) } }}