Export-CSV only gets the “Length”

前端 未结 1 1386
别跟我提以往
别跟我提以往 2021-01-27 05:30

when I try to export to a CSV list, I only get all number for \"Length\" .Count property until the split point is reached, then split the CSV array to a new file w

相关标签:
1条回答
  • 2021-01-27 06:19

    Export-CSV is built to take PSCustomObjects as input, not lines of text.

    $thisCSV = Get-Acl $path | Select-Object -Expand Access |
        Select-Object @{n='Path';e={$path}}, IdentityReference, AccessControlType,
                      FileSystemRights |
        ConvertTo-Csv
    

    The output of this line will be something like:

    #TYPE Selected.System.Security.AccessControl.FileSystemAccessRule
    "Path","IdentityReference","AccessControlType","FileSystemRights"
    "c:\test","BUILTIN\Administrators","Allow","FullControl"
    

    At least three lines, an array of string. What properties does an array of string have?

    PS C:\> 'a','b' | Get-Member -MemberType Property
    
    
       TypeName: System.String
    
    Name   MemberType Definition       
    ----   ---------- ----------       
    Length Property   int Length {get;}
    

    Length. The only property you see in the CSV, because Export-CSV is exporting all the properties, and that's the only property.

    Fix: Remove | ConvertTo-CSV from the Get-ACL line, leave your custom objects as custom objects and let the export handle converting them.

    (This should also fix the counting, because it's not counting 3+ lines of text while trying to export 1+ line of data every time).

    0 讨论(0)
提交回复
热议问题