Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2606
  • Last Modified:

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?
0
Blowfelt82
Asked:
Blowfelt82
1 Solution
 
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now