Search code examples
azurepowershellazure-data-lake

How to Export the GetFolderContent $ rootFolder value in CSV file using powershell


I have been trying to find out the way to export the list of Folders in CSV file to Azure DataLake Directly . I have found a Powershell shell toolkit snipet code and trying to export . but could not find out the way . Pls help! below is the line am trying to export

GetFolderContent $rootFolder


Solution

  • You can directly output to the csv file, the code below works at side:

    function GetFolderContent 
    {
     Param(
     [string]$rootFolder
     )
    
      $items = Get-AzureRmDataLakeStoreChildItem -Account "xxx" -Path $rootFolder
       Write-Host "$rootFolder" 
       $rootFolder >> "d:\test\222.csv"
    
       foreach ($item in $items) 
       {
         if ($item.Type -eq "DIRECTORY") 
         {
            $nextFolder = $item.Name 
    
             if ($rootFolder -eq "\") 
             {
               GetFolderContent $nextFolder 
             }
             else
             {
               GetFolderContent $rootFolder/$nextFolder
             }
         }
       }
          return $null 
    } 
    
    
       $rootFolder = "/" 
    
       GetFolderContent $rootFolder