【问题标题】:Powershell -recursive in Azure Data Lake StoreAzure Data Lake Store 中的 Powershell -recursive
【发布时间】:2016-12-22 02:16:55
【问题描述】:

有人知道如何列出数据湖存储和子目录中目录中的每个文件吗?显然-recursive 指令不像在正常环境中那样工作

我需要在 Azure Data Lake Store 中运行此脚本,(它在我的计算机上正常运行)

$Quarentine = "C:\PSTest\QUARENTINE"

$validate = "C:\PSTest\Files"

get-childitem $validate -rec -af | Where-Object {$_.FullName -notmatch "^C:\\PSTest\\Files\\(.+\\)*(XX.+)\.(.+)$"} | 
move-item -destination {"C:\PSTest\QUARENTINE\"+ $_.BaseName +("{0:yyyyMMddHHmmss}" -f (get-date)) + $_.Extension}

我正在使用命令Get-AzureRmDataLakeStoreChildItem 显然不支持-recursive

有人可以帮帮我吗?

谢谢

【问题讨论】:

    标签: powershell azure recursion azure-data-lake data-lake


    【解决方案1】:

    这是一种递归方式(注意:它不能很好地扩展,因为它对每个子目录进行 API 调用并且没有并行化,并且因为它将所有文件存储到内存中)。

    function Get-DataLakeStoreChildItemRecursive ([hashtable] $Params) {
        $AllFiles = New-Object Collections.Generic.List[Microsoft.Azure.Commands.DataLakeStore.Models.DataLakeStoreItem];
        recurseDataLakeStoreChildItem -AllFiles $AllFiles -Params $Params
        $AllFiles
    }
    
    function recurseDataLakeStoreChildItem ([System.Collections.ICollection] $AllFiles, [hashtable] $Params) {
        $ChildItems = Get-AzureRmDataLakeStoreChildItem @Params;
        $Path = $Params["Path"];
        foreach ($ChildItem in $ChildItems) {
            switch ($ChildItem.Type) {
                "FILE" {
                    $AllFiles.Add($ChildItem);
                }
                "DIRECTORY" {
                    $Params.Remove("Path");
                    $Params.Add("Path", $Path + "/" + $ChildItem.Name);
                    recurseDataLakeStoreChildItem -AllFiles $AllFiles -Params $Params;
                }
            }
        }
    }
    
    Get-DataLakeStoreChildItemRecursive -Params @{ 'Path' = '/Samples'; 'Account' = 'youradlsaccount' }
    

    【讨论】:

      【解决方案2】:

      我采用了另一种方法,但答案是我自己做递归函数

      function Get-DataLakeStoreChildItemRecursive ([string]$path, [string]$account, [string]$quarantine) {
      
          $dirs = Get-AzureRmDataLakeStoreChildItem -Account $account -Path $path
      
          foreach ($dir in $dirs) {
              switch ($dir.Type) {
                  "FILE" {
                      if(($path + $dir.Name) -match "^/adls-dev/raw/amp/(.+/)*(amp.+)\.(.+)$") {
                      }
                      else {
                          $to = $quarantine + ("{0:yyyyMMddHHmmss}-" -f (get-date)) + $dir.Name
                          Move-AzureRmDataLakeStoreItem -AccountName $account -Path ($path + $dir.Name) -Destination $to
                      }
                  }
                  "DIRECTORY" {
                      $q = ($quarantine + $dir.Name + '/')
                      $test = Test-AzureRmDataLakeStoreItem -AccountName $account -Path $q
      
                      if($test -eq $False) {
                          New-AzureRmDataLakeStoreItem -AccountName $account -Path $q -Folder
                      }
      
                      Get-DataLakeStoreChildItemRecursive ($path + $dir.Name + '/') $account $q
                  }
              }
          }
      }
      
      Get-DataLakeStoreChildItemRecursive "/adls-dev/raw/amp/" "asdf" "/adls-dev/quarantine/"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-10-06
        • 1970-01-01
        • 1970-01-01
        • 2018-11-08
        • 2018-06-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多