PowerShell to extract a specific column from csv and save to a variable

My keys.csv file is as follows

 PrjKey BldKey      key
 LS     LOOKUPSNAP1 LS-LOOKUPSNAP1
 LS     LSUH3       LS-LSUH3
 LSPERF LPMDS0      LSPERF-LPMDS0
 LSPERF LSP0        LSPERF-LSP0

I want to extract the columns of the "key" values ​​and store in a variable. I tried this

 Import-Csv .\keys.csv  | select key | ft -hide

the output has an empty line at the top. How can I fix it. I want these 4 values ​​to be "stored in a variable". Yes, I do not want to save the output as csv again.

Can anybody help?

+4
source share
1 answer

Select-Object, , . , , , Select-Object key , , . Format-cmdlets, . . ..

$keys = Import-Csv .\keys.csv | select -ExpandProperty key

PowerShell

$keys = (Import-Csv .\keys.csv).key
+4

Source: https://habr.com/ru/post/1610814/


All Articles