PowerShell to extract specific column from csv and store in a variable

后端 未结 1 880
长情又很酷
长情又很酷 2020-12-16 06:13

My keys.csv file looks like this

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


        
相关标签:
1条回答
  • 2020-12-16 06:31

    You had the right idea of using Select-Object to get the one property you want. The two issues you had was that Select-Object key returns and object array with a key property when it looks like you just want string array of keys. Also never use Format-cmdlets when you want to save the data or use it in another form. They destroy objects for the purpose of display data on the screen. So that all being said..

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

    Depending on your PowerShell version

    $keys = (Import-Csv .\keys.csv).key
    
    0 讨论(0)
提交回复
热议问题