How to retrieve Output from Remote Job

This topic contains 6 replies, has 4 voices, and was last updated by  Asrar 1 year, 7 months ago.

  • Author
  • #56101



    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.

  • #56102

    Don Jones

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

    • #56138


      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.

  • #56162

    Max Kozlov

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

    btw, Invoke-Command already return Computername as PSComputerName

  • #56170

    Don Jones

    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.

  • #56207

    Dan Potter

    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.

    • #56218


      Thank you very much, Don.

You must be logged in to reply to this topic.