Skip to content

Instantly share code, notes, and snippets.

@milesgratz
Created April 14, 2017 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milesgratz/b13bb116df7bd3636766d62fb3a2d96b to your computer and use it in GitHub Desktop.
Save milesgratz/b13bb116df7bd3636766d62fb3a2d96b to your computer and use it in GitHub Desktop.
Using -match with array of objects
$Source = "txt","csv","pdf","xlsx","docx"
$Find = "csv","pdf"
$Source | ForEach-Object {
# does not work
# -match cannot find item in array
If ($_ -match $Find)
{
$_
}
# works
# creates (csv|pdf) join
If ($_ -match ($Find -join "|"))
{
$_
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment