0

I can't figure out how to get the computernames that did not respond when using -asjob, could someone advise?

try{
    gwmi "Win32_OperatingSystem" -ComputerName $ordis -asjob  
    $resu=get-job | ? {$_.psjobtypename -eq "wmijob" } |wait-job |receive-job
}
catch{"error"}
$resu | select PSCOMPUTERNAME, @{name="lastboottime";expression={$_.converttodatetime($_.lastbootuptime)}} |sort lastboottime |ft
remove-job * -force

some hosts failed with the following error but I don't know which ones

Le serveur RPC n'est pas disponible. (Exception de HRESULT : 0x800706BA)
+ CategoryInfo : InvalidResult : (:) [], COMException
+ FullyQualifiedErrorId : JobStateFailed

3
  • For such scripts I use a CSV file with computer names. Import-CSV yield a collection to iterate. I save query results in another collection, then update the CSV fields (for hosts that responded) and save it with Export-CSV. Jun 6, 2014 at 9:03
  • @AlexanderObersht you're not taking the benefits of parallel processing like this Jun 6, 2014 at 9:12
  • I use parallel processing for queries. Processing the results takes negligible time. If you're interested I can post my code. Jun 6, 2014 at 9:16

1 Answer 1

1

Add another line to capture failed jobs after $resu | select.. statement, try/catch is not going to work as you are spawning wmi queries into separate run spaces.

....
Get-Job -State Failed | Select-Object -ExpandProperty Location
remove-job * -force
1
  • I had to loop through childjobs to get the information : get-job -state failed |select -expand childjobs | ?{$_.state -eq "failed"} |select -expand location Jun 6, 2014 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.