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

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
  • 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. – Alexander Obersht Jun 06 '14 at 09:03
  • @AlexanderObersht you're not taking the benefits of parallel processing like this – Loïc MICHEL Jun 06 '14 at 09:12
  • I use parallel processing for queries. Processing the results takes negligible time. If you're interested I can post my code. – Alexander Obersht Jun 06 '14 at 09:16

1 Answers1

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
Raf
  • 9,681
  • 1
  • 29
  • 41
  • I had to loop through childjobs to get the information : `get-job -state failed |select -expand childjobs | ?{$_.state -eq "failed"} |select -expand location` – Loïc MICHEL Jun 06 '14 at 10:22