Luc,
Thanks for the tips (also from the PM's)
I created a function with a second while loop, that get's kicked off almost at the end of the script.
It does the last error handling for the tasks.
Here is the code:
#CHECK THE TASK
#DO WE HAVE MORE THAN $MAXTASK TASKS RUNNING ?
while($tasks.Count -ge $maxTask)
{
#PUT ALL TASK OBJECT ON THE PIPE AS (NAME,VALUE) WHERE VALUE IS THE ACTUAL TASK OBJECT
$tasks.GetEnumerator() | % {
#GET THE LATEST STATUS OF THE TASK
$gettaskstate = get-view $_.value
$taskstate = $gettaskstate.info.state
$taskname = $_.Name
#CHECK IF THE TASK IS NOT QUEUED NOR RUNNING
if($taskstate -ne "running" -and $taskstate -ne "queued")
{
#CHECK THE OUTCOME OF THE TASK
if ($taskstate -eq "error")
{
WRITE_LOG "[ERROR] DEPLOYING: $taskname"
$tasks.Remove($_.Key)
#JUMP OUT OF THE FOREACH LOOP
continue
}
else
{
WRITE_LOG "[SUCCESS] DEPLOYING: $taskname"
$tasks.Remove($_.Key)
#JUMP OUT OF THE FOREACH LOOP
continue
}
}
}
sleep 5
}
And the code for the last task in the hash array:
Function CHECK_TASKS
{
#CHECK THE TASK
#DO WE HAVE MORE THAN $MAXTASK TASKS RUNNING ?
while($tasks.Count -gt 0)
{
#PUT ALL TASK OBJECT ON THE PIPE AS (NAME,VALUE) WHERE VALUE IS THE ACTUAL TASK OBJECT
$tasks.GetEnumerator() | % {
#GET THE LATEST STATUS OF THE TASK
$gettaskstate = get-view $_.value
$taskstate = $gettaskstate.info.state
$taskname = $_.Name
#CHECK IF THE TASK IS NOT QUEUED NOR RUNNING
if($taskstate -ne "running" -and $taskstate -ne "queued")
{
#CHECK THE OUTCOME OF THE TASK
if ($taskstate -eq "error")
{
WRITE_LOG "[ERROR] DEPLOYING: $taskname"
$tasks.Remove($_.Key)
#JUMP OUT OF THE FOREACH LOOP
continue
}
else
{
WRITE_LOG "[SUCCESS] DEPLOYING: $taskname"
$tasks.Remove($_.Key)
#JUMP OUT OF THE FOREACH LOOP
continue
}
}
}
sleep 5
}
}
The case is closed :smileysilly: