How to retrieve Output from Remote Job


I am trying to query a registry on several 2008 R2 machines using ICM and -asjob parameter. I use the following code

 icm -computername $_ { $x = "hklm:\software\policies\citrix\ima"; write-output "$($env:computername), $($x.loadevaluator)" }

I then use, get-job | wait-job | receive-job

Is there a better way to do this.

That’s what I’d probably do. What do you feel is wrong with it?

Is there a way that each icm session can return an object, so that I can use export-csv to format the output in a more cleaner way.

Current approach looks very bland.

you don’t try to return object and you doesn’t get object :slight_smile:
tro to use [PSCustomObject] or New-Object instead of just write-output $somearray
the examples everywhere…

btw, Invoke-Command already return Computername as PSComputerName

We don’t worry about “bland” in PowerShell :).

Each job that you create using Invoke-Command actually has one child job per computer. There’s a parameter of Show-Job that will let you see the child jobs, in fact. So you can retrieve one “session” (child job) at a time.

The results of each job are whatever your code outputs.

icm -computername $_ { $x = "hklm:\software\policies\citrix\ima"; write-output "$($env:computername), $($x.loadevaluator)" }

Right now, you’re outputting a string object, so that’s what the job’s results will be. If you want something “cleaner” in terms of PowerShell:

icm -computername $_ { $x = "hklm:\software\policies\citrix\ima"
 New-Object -Type PSObject -Prop @{'ComputerName'=($env:computername) ; 'LoadEvaluator' = $x.loadevaluator }

That’ll produce an object having two properties.

Start-job with a name would be easier. When you get into complex stuff like job monitoring, tracking, updating grids it’ll come in handy.

Thank you very much, Don.