I managed to solve that myself:
1. Invoke-Command as a job.
2. When all remote jobs are invoked I am starting a loop that check if all my jobs are complete:
While($true){
Write-Host ((Get-Date).ToString('HH:mm:ss')) -ForegroundColor Green;
$allFinished = $true;
for($i = 0; $i -le (Get-Job).Count - 1; $i++){
$currentJobCompleted = (Get-Job)[$i].State -eq 'Completed';
$allFinished = $allFinished -and $currentJobCompleted;
}
if($allFinished -eq $true){
break;
}else{
for($i = 0; $i -le (Get-Job).Count - 1; $i++){
Write-Host ((Get-Job)[$i].Location + ' ' + (Get-Job)[$i].State) -ForegroundColor Gray;
}
}
Start-Sleep -Seconds 10;
}
Remove-PSSession *;
after all jobs complete - i execute
Receive-job <job id>
easy as that!
hope that helps anyone