Hello All,So I have 4 SQL Agent jobs that all run PowerShell scripts that utilize the multithreading abilities of PowerShell but I am running into issues. These 4 jobs are set to run every 5 minutes because they collect perfmon stats about our servers. Each job takes between 1-2:30 minutes to run to completion, each job is set to grab data for approximately 75 servers, and each PowerShell script is set to have a maximum of 6 threads running at a time. The issue I am encountering is SQL Agent will mark the job as failed if the PowerShell script reaches the end of the script but there are still active threads. I currently have it set up to check the total number of running threads and when that count reaches zero, it will finish the script. However, with all 4 of these jobs running, the script will count the total number of running threads from any of the scripts to calculate if the script is finished or not and this will get hung as the day goes on and the run times begin to overlap.Does anyone know of a good way to manage how many threads are running for a given SQL Agent job and only finish the script if the PowerShell threads for the current script have all finished executing?
↧