【问题标题】:Azure powershell changes to check for file in Azure Data lake storage Gen 1 and trigger a BAT scriptAzure Powershell 更改以检查 Azure Data Lake Storage Gen 1 中的文件并触发 BAT 脚本
【发布时间】:2019-10-14 12:45:02
【问题描述】:

一旦文件在 Azure Data Lake Storage - Gen 1 中可用,我需要运行 BAT 文件。我有 PowerShell 脚本,它从我的 C:\Temp 执行文件夹检查,但我需要将其更改为 Azure数据湖存储路径位置。

我使用 AzureRmDataLakeStoreItem 而不是 C:\Temp,但在这方面遇到了错误。

以下是 PS 脚本:

 Param (
    #[string]$Path = "C:\Temp"
    [string]$Path = "Test-AzureRmDataLakeStoreItem -AccountName "aruntesting1" -Path "/MyFiles/test.csv" "
    )

### Look for any files from the path mentioned above
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = $Path
    $watcher.Filter = "*.*"
    $watcher.IncludeSubdirectories = $true
    $watcher.EnableRaisingEvents = $true  

### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
    $action = { 
                $A = Start-Process -FilePath C:\Users\arsivana\Desktop\Arun\Project\xyz\test.bat -Wait -passthru;$a.ExitCode
              } 


### Events to be watched 
    Register-ObjectEvent $watcher "Created" -Action $action
    Register-ObjectEvent $watcher "Changed" -Action $action
    Register-ObjectEvent $watcher "Deleted" -Action $action
    Register-ObjectEvent $watcher "Renamed" -Action $action
    while ($true) {sleep 2}

【问题讨论】:

  • 据我所知,如果你在本地运行PowerShell脚本,你需要先下载bat文件,然后才能运行bat文件。文件下载方法请参考docs.microsoft.com/en-us/azure/data-lake-store/…
  • Jim - 我的桌面文件夹中有这个 powershell 脚本,它会使用 Windows 调度程序每 10 分钟运行一次。但是只有在 Azure 中有可用文件时才会触发 test.bat 文件数据湖存储..所以在这种情况下,如果 test.csv 文件可用,那么 test.bat 应该被触发..
  • 据我了解,您想检查 Azure 数据湖存储中是否存在一个文件。并且 bat 文件在本地。对吗?
  • 另外,能否请您提供错误信息?
  • 据研究,命令Test-AzureRmDataLakeStoreItem用于检查账户中是否存在文件。如果文件存在,则返回true。否则,它返回false。所以我觉得可以用脚本触发$result = Test-AzureRmDataLakeStoreItem -Account $account -Path $path -PathType File if($result){ Start-Process }

标签: azure powershell azure-data-lake


【解决方案1】:

根据我的研究,命令Test-AzureRmDataLakeStoreItem用于检查帐户中是否存在文件。如果文件存在,则返回 true。否则,它返回 false。更多详情请参考document。所以我觉得可以用脚本来触发

$result = Test-AzureRmDataLakeStoreItem -Account $account -Path $path -PathType File
 if($result){ Start-Process }

【讨论】:

  • @arun 如果你没问题,请接受答案。它可以帮助有类似问题的人。
猜你喜欢
  • 2020-11-22
  • 2019-09-23
  • 2020-01-24
  • 1970-01-01
  • 1970-01-01
  • 2021-02-28
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多