user3201928
user3201928

Reputation: 380

how to select particular column after importing csv

I used import-csv cmdlet and imported csv file with many columns and row.snapshot of the imported csv

I want to choose only account number field which is not 0 and separate them "," and store it to string. How can i choose that particular field from the import-csv list?

Upvotes: 0

Views: 882

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

Use Select-Object -ExpandProperty to grab the value of just a single property, then use Where-Object to filter out those with value 0:

$AccountNumbers = Import-Csv .\data.csv |Select-Object -ExpandProperty 'Account Number' |Where-Object {$_ -ne "0"}

And then use the -join operator to produce your string:

$CommaSeparatedString = $AccountNumbers -join ','

Upvotes: 2

Related Questions