question

VaibhavChaudhari avatar image
0 Votes"
VaibhavChaudhari asked RichMatheisen-8856 answered

Get the powershell output either propertly formatted out or directly in CSV

Below code prints output with empty lines in between. I have to manually copy output, remove empty lines and add comma in between and then copy to excel.

How can we have have output like or directly save in CSV
folder1, 12.34, 555,666
folder2, 0.44, 11,22

 $paths = @("/folder1","/folder2")
    
 foreach($path in $paths)
 {
     $details = Get-AzDataLakeStoreChildItemSummary -Account $Gen1Account -Path $path
     $details | select @{name = "Folder"; expression = {$path}}, @{name="SizeInGB"; expression = {$_.length/1gb} } , DirectoryCount, Filecount | Format-Table -AutoSize -HideTableHeaders
 }


windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Does this work for you?

 $paths = @("/folder1","/folder2")
        
 $paths |
     ForEach-Object {
         $folder = $_
         Get-AzDataLakeStoreChildItemSummary -Account $Gen1Account -Path $_ |
             Select-Object @{name = "Folder"; expression = {$folder}}, @{name="SizeInGB"; expression = {$_.length/1gb} }, DirectoryCount, Filecount
     } | Export-CSV -Path <some-file-path> -NoTypeInformation
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.