Solved

Import-Csv with powershell when headers have spaces.

Posted on 2013-01-10
3
2,167 Views
Last Modified: 2013-01-28
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
Comment
Question by:Blowfelt82
3 Comments
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 38762323
import-csv file.csv | Where-Object {$_."File Name" like "*.txt"}
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 38762431
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
 
LVL 40

Expert Comment

by:Subsun
ID: 38762486
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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question