Solved

Import-Csv with powershell when headers have spaces.

Posted on 2013-01-10
3
2,120 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 18

Accepted Solution

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

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now