0

i try to read data into powershell with a csv file, i want to achieve something like that


name 
------
peter 
hans

but i get something like this:

name;alter 
---------- 
peter;klaus
hans;dieter

my code looks like this:

$CSV= Import-Csv \\D\test.csv

$csvFiles = $CSV 

$csvFiles 

i know that i have to select in following code that i only want "names" but if i edit my code to:

$CSV= Import-Csv \\D\test.csv

$csvFiles = $CSV | Select-Object 'name'

$csvFiles 

i only get

name
----

Edit:

enter image description here

the file is saved csv utf8

csv in notepad++

name;alter
peter;klaus
hans;dieter
du7ri
  • 67
  • 1
  • 10
  • if your delimiter is not a comma, then you likely need to use the `-Delimiter` parameter to set it to the correct char. your sample seems to use a semicolon. – Lee_Dailey Jul 23 '21 at 11:55
  • @Lee_Dailey i also tought that but it dont work that way too – du7ri Jul 23 '21 at 11:57
  • 4
    @du7ri Please expand on "dont work". Does `Import-Csv \\D\test.csv -Delimiter ';'` produce an error? Same output? Different output? Computer catched on fire? – Mathias R. Jessen Jul 23 '21 at 12:26
  • @MathiasR.Jessen i get the output `name; -----` i dont know if somehing isnt right with my csv, but i dont think something is wrong with it – du7ri Jul 23 '21 at 12:29
  • 2
    @du7ri - please add to your Question - [A] the 1st 3 lines of your csv file wrapped in code formatting. ///// [B] the result you get when importing that part of that file - again, wrapped in code formatting. – Lee_Dailey Jul 23 '21 at 12:37
  • @Lee_Dailey part b i dont got – du7ri Jul 23 '21 at 12:49
  • 1
    Open your csv with notepad CTRL+A > CTRL+C > Edit your question > CTRL+V > Save. – Santiago Squarzon Jul 23 '21 at 12:52
  • 1
    @du7ri - please, do not post _images of code/errors/data._ why lookee ... Why not upload images of code/errors when asking a question? - Meta Stack Overflow — https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question – Lee_Dailey Jul 23 '21 at 13:01
  • 1
    If your CSV looks like that then Mathias's answer should be working fine – Santiago Squarzon Jul 23 '21 at 13:11
  • i tried again @SantiagoSquarzon now it works, thanks all ! – du7ri Jul 23 '21 at 13:15

0 Answers0