Hello everyone,
I am struggling to understand the way the parameters for cmdlet in the pipleline are bound. To elaborate, I came across the below article from Boe Proxs website
http://learn-powershell.net/2015/03/31/introducing-poshrsjob-as-an-alternative-to-powershell-jobs/
In that PoshRSjob module, I am looking at the Start-RsJob cmdlet in particular.
He has shown the below example where I am having trouble understanding:
$Test = 42 1..5|Start-RSJob -Name {"TEST_$($_)"} -ScriptBlock { Param($Object) $DebugPreference = 'Continue' $PSBoundParameters.GetEnumerator() | ForEach { Write-Debug $_ } Write-Verbose "Creating object" -Verbose New-Object PSObject -Property @{ Object=$Object Test=$Using:Test } }
My understanding is that the following parameterset is being employed in the above Start-RSJob command:
Start-RSJob [[-ScriptBlock] <scriptblock>] [-InputObject <Object>] [-Name <Object>] [-ArgumentList <Object>] [-Throttle <int>] [-ModulesToImport <string[]>] [-PSSnapinsToImport <string[]>] [-FunctionsToLoad <string[]>] [<CommonParameters>]
In this case what I am struggling to understand is
- How is the pipeline object (1..5) bound to the Param($object) in the scriptblock? What is the parameter binding rule being employed here so as for the pipeline object to end up inside the Scriptblock?
- Secondly, what is the significance of [-inputObject <object>] parameter in the above parameterset which however is not explicitly used in the Start-RSJob command above? Does it mean that as long as the object comes from the pipeline we do not need to use this inputobject parameter explicitly, instead it is inferred?
May be a PowerShell parameter binding-101 question but I wanted to fully understand.
- Edited by Steve DSouza 20 hours 29 minutes ago