Using PowerShell to Submit Jobs based on File Triggers


A common requirement is to dynamically submit a Job that processes a file based on the file's status. This is simple, straight forward and reliable when there is only a single file arriving - configure a File Trigger Element on the Job that processes the file. However, in cases where there are multiple files arriving, the recommended approach is slightly different.

JAMS provides a PowerShell module available that can assist us with this scenario. The module contains cmdlet's that allow us to interact with our environment. Specifically, the cmdlet, Submit-JAMSEntry, is used to submit a Job to the schedule.

A JAMS Job can be created from the following PowerShell script. The script loops through a list of files and utilizes the cmdlet - Submit-JAMSEntry - to submit a JAMS Job for each of the files in the collection. A File Trigger Element can be defined on the Job to initiate it when the required files appear.

Be sure to update the script where noted.


#  Import the JAMS PowerShell module
Import-Module JAMS

#  Modify the path to match the defined File Trigger Element
$fileList = Get-ChildItem C:\Incoming\*.dat

# # Create an array where we will save the JAMS Entry number of job we submit#
$entryList = @()
# # Submit a JAMS Job to process each of the files # foreach ($file in $fileList) { # # get the filename from the file object # $filename = $file.FullName # # Update "ProcessFile" with the name of the JAMS Job. This job must have a parameter named "filename" # The "-UseVariables" parameter tells Submit-JAMSEntry to look for a PowerShell # Variable - defined above - that matches each parameter in the job and use the variable value # as the value for the parameter # $lastSubmit = Submit-JAMSEntry ProcessFile -UseVariables # # Write some information to the log file # write-host "Entry " $lastSubmit.JAMSEntry " submitted to process $filename" # Save the Entry number # $entryList += $lastSubmit.JAMSEntry } # # We have submitted a job to process each file, # now we will wait for all of them to complete. # Wait-JAMSEntry $entryList -verbose
Have more questions? Submit a request


  • Avatar
    David Puckett

    A sleep statement may be needed to delays loop iterations
    Sleep -Seconds 5