Export-CSV exports length but not name

前端 未结 5 1269
迷失自我
迷失自我 2020-11-28 12:23

I have this code that I am running from powershell. When I run it without the export-csv i get all the folder names on the screen.

dir | select -expand fulln         


        
5条回答
  •  被撕碎了的回忆
    2020-11-28 12:59

    This is another way to handle this issue:

    1. Out-File outputs by default

    Define the master array list

    $MASTER_ARRAY_LIST =  [System.Collections.ArrayList]@()
    

    Define the output filename

    $OutputFilename="C:\TEMP\MyOutputFile.csv"
    
    ForEach ( $Something in $List_of_Somethings) {
        $CURRENT_RECORD_DETAILS = New-Object PSObject -Property @{'name'=$($Something.Name);'fullname'=$($Something.FullName);'id'=$($Something.ID)}
        $MASTER_ARRAY_LIST.Add( $CURRENT_RECORD_DETAILS ) > $null
    }
    
    $MASTER_ARRAY_LIST.ToArray() | Select-Object -Property name,fullname,id | Export-Csv -Path $OutputFilename -NoTypeInformation
    

提交回复
热议问题