csv PowerShell变量仅选择一列

tyg4sfes  于 12个月前  发布在  Shell
关注(0)|答案(1)|浏览(86)

我在PowerShell中导入CSV时遇到问题。当我试图获取我导入的数据时,我只得到一个空变量作为响应。
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

无论如何,当我导入它时,只需使用以下命令:$csvImport = Import-CSV -Path "C:\Path\to\CSV.csv" -Delimiter ";"
它工作了,当我输入$csvImport时,我得到了一个输出。有人能告诉我如何选择单列吗?我试过$csvImport.BOKNR-但它只是返回一个空变量。我需要改变什么。任何解决方案都值得赞赏。

yr9zkbsy

yr9zkbsy1#

你的例子在我的机器上有效。

$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

相关问题