2 Replies Latest reply on Aug 7, 2017 8:20 AM by Suparna Jain

    Running schedule on a event

    Suparna Jain

      Hi All,

       

      I am trying to run a schedule when a file is created. It goes to the point the to login to the Bin folder then does nothing.Can anyone help please?

       

      ## ENTER FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO

          $watcher = New-Object System.IO.FileSystemWatcher

          $watcher.Path = “d:\test\”

          $watcher.Filter = “file1.*”

          $watcher.IncludeSubdirectories = $true

          $watcher.EnableRaisingEvents = $true 

       

        ### DEFINE ACTIONS POST ANY EVENT IS DETECTED

          $action = { $path = $Event.SourceEventArgs.FullPath

           $changeType = $Event.SourceEventArgs.ChangeType

            $logline = “$(Get-Date), $changeType, $path“

                    

             Set-Location “D:\Tableau Server\10.3\bin”

       

        ### TABLEAU : This command runs when ran independently

      $TabCMD=.\tabcmd runschedule "test" -s https://srv-******* -u ****** -p *******

                    

      Invoke-Expression-Command:$TabCMD

      write-host ‘Its done!!’ 

      Add-content “D:\log.txt” -value $logline         

       

        ### DECIDE WHICH EVENTS SHOULD BE WATCHED + CHECK EVERY 5 SECONDS 

      $created = Register-ObjectEvent $watcher “Created” -Action $action

      while ($true ) {sleep 5}

       

       

      Regards

      Suparna