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

Vaibhav Chaudhari 38,681 Reputation points
2020-08-05T14:33:47.467+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,831 Reputation points
    2020-08-05T14:47:30.567+00:00

    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
    
    0 comments No comments

0 additional answers

Sort by: Most helpful