【发布时间】: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