Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 {$ -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

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)

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 {$ -eq $id} | foreach { $_.configData }

$configList | where {$ -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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .