Reputation: 380
I used import-csv cmdlet and imported csv file with many columns and row.
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
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