Submit Jobs to More Than One Agent From an Agent List

Follow

This job will read a listing of agents from a text file, and submit a job in the list to each agent.  This job also checks the status of each job it submitted, and writes them out to its own log file.


 

Import-Module JAMS
#
# Read a file which contains a list of Agents. The agents list contains a list with each agent name on on each line of the text file.
#
$agentList = Get-Content C:\Temp\AgentList.txt
#
# Initialize an array to hold all of the jobs that we are about to submit
#
$processEntries = @()
#
# Submit a job for each of the things in the file
#
foreach($agent in $agentList)
{
    #
    # Submit Each job using Submit-JAMSEntry to each agent in the list.  We submit the Sleep120 job for each agent in the list that we found, replace Sleep120 with the path to the job you want to submit for each agent.
    #
    $submitResult = Submit-JAMSEntry \Sleep120 -Agent $agent -Verbose
    #
    # Add the JAMSEntry number to the array
    #
    $processEntries += $submitResult.JAMSEntry
}
#
# Wait for all of the jobs we submitted to complete
#
Wait-JAMSEntry $processEntries -verbose
#
# Now, check the status of each entry
#
foreach($entry in $processEntries)
{
    $entryInfo = Get-JAMSEntry -Entry $entry
    write-host "Final status of entry " $entryInfo.JAMSEntry "is" $entryInfo.FinalStatus
}

 

Have more questions? Submit a request

Comments