Author Posts

October 26, 2016 at 2:39 pm


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.

October 26, 2016 at 2:41 pm

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

October 27, 2016 at 3:32 am

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.

October 27, 2016 at 12:30 pm

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

October 27, 2016 at 1:29 pm

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.

October 27, 2016 at 2:03 pm

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.

October 27, 2016 at 2:16 pm

Thank you very much, Don.