This might take you < 1 minute to read.

To run multiple scripts in multiple servers can be pain… I have created a way to dynamically run scripts on each server and yet only trigger on file per server. If you want to trigger another script just add the script in the “$global:TriggerFolder”-folder and it will be run next time this script is run.

This might be very handy if you executing powershellscripts as a surveillance method.

#Loading Framework, the only static path in the script.
. ("c:ScriptsloadFramework.ps1")

Get-Job | Remove-Job

#retrieve all ps1-files trigger them in parallell
ForEach ($file in (Get-ChildItem ($TriggerFolder + "*.ps1") ) ) {
	start-job -Name $file.Name -filepath ($TriggerFolder+$file.Name) | Out-Null
while ((Get-Job | Where-Object {$_.state -match 'running'}).count -gt 0) {
	sleep 1

# Get all jobs execution time. Is very handy to see if a script execution differs from before.
$hashScripts = @{}
foreach ($job in Get-Job) {
	$hashScripts.Add($, ($job.psEndTime - $job.psBeginTime ) )
# Clear all jobs
Get-Job | Remove-Job

The framework-file that is loaded looks like this (very reduced).

# Folders
$global:ScriptFolder    = "c:Script"
$global:CoreFolder      = $ScriptFolder + "Core"
$global:FunctionFolder  = $ScriptFolder + "Function"
$global:TriggerFolder   = $ScriptFolder + "Triggers"
$global:TempPath        = $ScriptFolder + "temp"

$global:DownloadSource  = "https://url/to/function/repository/"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.