Import-Csv with powershell when headers have spaces.

I am using the following command to try and import a CSV file with powershell

import-csv file.csv | Where-Object {$_."File Name" like ".txt"}

This does not seem to work and I am sure there is an easy solution. All I want to do is read an excel file and return all rows where the filename field is like '.txt'.

Ideas?
Blowfelt82Asked:
Who is Participating?
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
import-csv file.csv | Where-Object {$_."File Name" like "*.txt"}
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
If you have difficulties to spot the difference (I had): The issue is that like needs wildcards. The space in your properties are no issue.
0
 
SubsunCommented:
Try with..
import-csv file.csv | Where-Object {$_."File Name" -like "*.txt"}
or
import-csv file.csv | Where-Object {$_."File Name" -match ".txt$"}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.