2
我想通過一個文件列表並檢查每個文件名是否與列表中的任何字符串匹配。這是我迄今爲止的,但它沒有找到任何匹配。我究竟做錯了什麼?PowerShell - 如何檢查字符串以查看它是否包含另一個帶有通配符的字符串?
$files = $("MyApp.Tests.dll","MyApp.Tests.pdb","MyApp.dll")
$excludeTypes = $("*.Tests.dll","*.Tests.pdb")
foreach ($file in $files)
{
$containsString = foreach ($type in $ExcludeTypes) { $file | %($_ -match '$type') }
if($containsString -contains $true)
{
Write-Host "$file contains string."
}
else
{
Write-Host "$file does NOT contains string."
}
}