2
votes

I need to run a BAT file once the file is available in Azure Data lake Storage - Gen 1. I have the PowerShell script which does the folder check from my C:\Temp, but I need this to be changed to Azure Data lake storage path location.

Instead of C:\Temp I use AzureRmDataLakeStoreItem, but facing errors in this.

Below is the PS Script:

 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}
1
As far as I know, if you run the PowerShell script on-premise, you need to download the bat file at first then you can run the bat file. Regarding how to download file, please refer to docs.microsoft.com/en-us/azure/data-lake-store/…Jim Xu
Jim - I have this powershell script in my desktop folder and it will run for every 10 minutes using Windows scheduler..but the test.bat file should get triggered only when there is a file available in Azure Data lake storage..so in this case if test.csv file is available then test.bat should get triggered..Arun S
According to my understanding, you want to check if one file exists in Azure data lake store. And the bat file is on-premises. Is that right?Jim Xu
Besides, could you please provide me the error message?Jim Xu
According to research, the command Test-AzureRmDataLakeStoreItem is used to check if a file exists in the account. If file exists, it returns true. Otherwise, it returns false. So I think you can use the script to trigger $result = Test-AzureRmDataLakeStoreItem -Account $account -Path $path -PathType File if($result){ Start-Process }.Jim Xu

1 Answers

0
votes

According to my research, the command Test-AzureRmDataLakeStoreItem is used to check if a file exists in the account. If file exists, it returns true. Otherwise, it returns false. For more details, please refer to the document. So I think you can use the script to trigger

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