How do I filter a string array (or list) in PowerShell using the ‘Match’ cmdlet?

Try this:

$FileNames = Get-ChildItem -Path "C:\Users\anagre\Desktop" -Filter *.csv

In your above code you didn’t use the $PSItem ($_) in your where clause, and if you want to use a wildchar you have got to use the -like operator:

$FileNames|where{$_ -like "*.csv"}

or

$FileNames|where{$_ -match ".csv"}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)