
If you want to find items in an array using a single string, you can use wildcards to match that item. Example:
$Search = "Brows*" Get-Service | where { $_.Name -like $Search }
But if you have multiple search strings (in an array)… You don’t get any result if you use this in the same way:
$Search = @("Brows*","Prin*","Win*") Get-Service | where { $_.Name -like $Search }
This example does not work unfortunatly. The operators -match and -contains also don’t work…
Solution:
Merge the array to a string and use it the same way like the first example, only now with the -match operator.
$Search = @("Brows*","Prin*","Win*") $SearchString = $Search -join "|" Get-Service | where { $_.Name -match $SearchString }
Leave a Reply