Question:
I have just started using PowerShell today, and I have an intention list files by a few patterns in an array, for instance:
1 2 3 4 5 |
$matchPattern = ( "SomeCompany.SaaS.Core.Mvc*", "SomeCompany.SaaS.Core.UI.Framework*" ); |
I want to list files in a $sourceDir
where any of the item in the above array matches.
I can do this, and it works:
1 2 3 4 5 |
foreach ($item in $matchPattern) { Get-ChildItem $sourceDir | Where-Object {$_.Name -like $item} } |
Just for learning purposes, can I do it in pipe-lining?
Something similar to this:
1 2 |
Get-ChildItem $sourceDir | Where-Object { $matchPattern -contains $_.Name } |
Answer:
You can just do:
1 2 |
gci "$someDir\*" -include $matchPattern |