PowerShell Variable select only one column

43 views Asked by At

I have a Problem with my CSV Import in Powershell. When i try to get the data that I imported I just get an empty variable as response.

CSV:

BOKNR;BOKN;AFSN;AFSK;AFAS;BOKNR+;AFCB
12340;xxxx;xxxx;xxxxxx;1;xxxx;25
12341;xxxx;xxxx;xxxxxx;1;xxxx;25
12342;xxxx;xxxx;xxxxxx;1;xxxx;25
12343;xxxx;xxxx;xxxxxx;1;xxxx;25
12344;xxxx;xxxx;xxxxxx;1;xxxx;25
12345;xxxx;xxxx;xxxxxx;1;xxxx;25

anyways When I import it and just with this command: $csvImport = Import-CSV -Path "C:\Path\to\CSV.csv" -Delimiter ";"

It works and I get an output when I just type $csvImport. Can someone tell me how to select single columns? I have tried with $csvImport.BOKNR - but it just returns me nothing like an empty variable. What do I need to change. Any solutions are appreciated.

1

There are 1 answers

1
David Trevor On

Your example works on my machine.

$csvImport = Import-CSV -Path "C:\Path\to\CSV.csv" -Delimiter ";"

$csvImport | ft

    BOKNR BOKN AFSN AFSK   AFAS BOKNR+ AFCB
    ----- ---- ---- ----   ---- ------ ----
    12340 xxxx xxxx xxxxxx 1    xxxx   25
    12341 xxxx xxxx xxxxxx 1    xxxx   25
    12342 xxxx xxxx xxxxxx 1    xxxx   25
    12343 xxxx xxxx xxxxxx 1    xxxx   25
    12344 xxxx xxxx xxxxxx 1    xxxx   25
    12345 xxxx xxxx xxxxxx 1    xxxx   25

$csvImport | Get-Member

       TypeName: System.Management.Automation.PSCustomObject

    Name        MemberType   Definition
    ----        ----------   ----------
    Equals      Method       bool Equals(System.Object obj)
    GetHashCode Method       int GetHashCode()
    GetType     Method       type GetType()
    ToString    Method       string ToString()
    AFAS        NoteProperty string AFAS=1
    AFCB        NoteProperty string AFCB=25
    AFSK        NoteProperty string AFSK=xxxxxx
    AFSN        NoteProperty string AFSN=xxxx
    BOKN        NoteProperty string BOKN=xxxx
    BOKNR       NoteProperty string BOKNR=12340
    BOKNR+      NoteProperty string BOKNR+=xxxx

$csvImport.BOKNR

    12340
    12341
    12342
    12343
    12344
    12345