I am running jobs on multiple servers , What is the most effective way that the get-job cmdlet can keep producing the results as soon as they are available or completed . The PROBLEM I am facing that when I try tio access the results some of them are not even completed.hence I get weird data and using remove-jobs kills the job very soon.
get-job | Remove-Job -force is killing the jobs too soon. The target is to get the job results as soon as they are complete and then removed.
$servers = gc .\servers.txt
$arr = @()
foreach ($server in $servers)
{
Invoke-Command -ComputerName $server -ScriptBlock {Get-StoragePool Storagepool01 | select -Property AllocatedSize ,size } -AsJob
}
$noofservers = get-job | measure
$details = get-job | Receive-Job
get-job | Remove-Job -force
while ($out1 -le $noofservers.Count)
{
$out1
$details[$out1].PSComputerName
$details[$out1].AllocatedSize/1TB
$details[$out1].size/1TB
$out1++
}