Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

this should be a really easy one but I can't seem to find an easy way.

For example, in Powershell and am using a CSV file, which is then used to look up some configuration data based on an ID. Here is what I have now, it works, but there has got to be a better way.

$configList = import-csv "C:\myconfig.csv"
$id = "5001"

$configList | where-object {$_.id -eq $id} | foreach-object{ $configData = $_.configData}

If use format-table etc, I always get the column header, which I would then have to cut off.

Again, this has got to be really easy and this isn't a show stopper. But there has to be a better way to get just the data out of a table without the column header.

share|improve this question

2 Answers 2

Not sure if this helps but you can load the csv file into an array and then using indices access the individual rows and for each row you can use the column name to access the individual cell.

$a = @(Import-CSV C:\myconfig.csv)
$a[0].ColA

Just change 'ColA' for the name of your column and remember rows are 0 indexed.

share|improve this answer

I know of two ways.

$configList | where {$_.id -eq $id} | foreach { $_.configData }

$configList | where {$_.id -eq $id} | select -ExpandProperty configData

(Style-wise, although I avoid aliases in scripts for clarity, I'm fine with where, foreach, and select, as I don't think that -Object adds anything.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.