Answered by:
Receive-Job Returns RunSpaceID

Question
-
Good Afternoon all,
Created a basic script which will start a job to find the size of a directory. In the start-job script Block, I am creating an object like below:
$Results = @{}
$Results.FilePath = "Filepath"
$Results.FizeSize = "FileSize"New-object -typeName PSObject -property $Results
The functionality is fine, however when I do get-job | Receive-JOB, I get a RunSpaceID as an additional Parameter. If however I do the following:
,@(New-Object -TypeName PSObject -Property $Results)
Then I get only the objects I require (this has to have a comma as well). My question is what does ,@() do?
Monday, June 5, 2017 1:26 PM
Answers
-
Same as this:
$null,@()
It creates an array with two elements - one is empty and one is an empty array. Also a short way to do this.
@(,@())
It is almost never needed if things are coded correctly but was used to avoid a bug in earlier versions of PS.
\_(ツ)_/
- Marked as answer by Satbir Bussan Tuesday, June 6, 2017 8:22 AM
Tuesday, June 6, 2017 8:07 AM
All replies
-
@() creates an array.
Try it like this:
start-job { [pscustomobject]@{ Name = 'joe' Age = 12 } } | Receive-Job -wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSSourceJobInstanceId
\_(ツ)_/
- Proposed as answer by Hello_2018 Tuesday, June 6, 2017 8:22 AM
Monday, June 5, 2017 6:28 PM -
Good Morning jrv, many thanks for that code, always good to learn different ways to complete tasks. I understand that @() creates an array however the results are very different compared to when I use @() and ,@(). Just curious to understand what the comma in front of the array declaration does.
As a side note, I have done something similar to yourself, where I have selected the parameters when working with the output (rather than excluding properties). Appreciate your assistance.
Tuesday, June 6, 2017 7:54 AM -
Same as this:
$null,@()
It creates an array with two elements - one is empty and one is an empty array. Also a short way to do this.
@(,@())
It is almost never needed if things are coded correctly but was used to avoid a bug in earlier versions of PS.
\_(ツ)_/
- Marked as answer by Satbir Bussan Tuesday, June 6, 2017 8:22 AM
Tuesday, June 6, 2017 8:07 AM