Background Jobs Continuously Running and Won't Complete
I use start-job and array to run multiple jobs in the bkgrnd, but for
those IPs that are found to be online, the job will not complete and keeps
running. The below is a modifed snippet from the larger script and works
fine for any IP that is offline, but for an IP that is online, the job
just continuously runs. winRM not an option since IA shop will not allow
it.
Thanks for any help that you can provide.
$sb = {
param ([string] $comp )
$rtn = "";
if ( Test-Connection $comp -Quiet -Count 1 )
{
$n = gwmi win32_ComputerSystem -ComputerName $comp | select name
| %{ $_.name}
$rtn += "$Comp online = name $n"
$rtn += $Error
}
else
{
$rtn += "$comp = Offline."
}
return $rtn;
}
$j = Start-Job -ArgumentList '10.251.150.10' -ScriptBlock $sb
while ($j.State -ne "Completed") {
$j | fl *
$j.ChildJobs | %{ $_ | fl * }
Start-Sleep -Milliseconds 500
}
$result = Receive-Job $j.id
$result
No comments:
Post a Comment