2

I am creating PowerShell cmdlets in C# by extending the PSCmdlet class. I need to get the entire Pipelined input to use in the C# code. I tried having a parameter with properties set as:

[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public Object Connection;

When I try to execute the cmdlet by piping in a list of items, I get one item at a time to process in the C# code.

$a=@("value1","value2")
$a | cmdlet-name

I need to get the entire piped input to process in my C# code. I found that this can be obtained in PowerShell using the $input variable. Is there a C# equivalent of this $input PowerShell variable?

1 Answer 1

1

Not that I know of. However, you can use the ProcessRecord method to accumulate pipeline objects (from the property bound to pipeline input) into a collection and then process the accumulated objects in your EndProcessing method.

Sign up to request clarification or add additional context in comments.

2 Comments

I am not sure but is it that for each pipelined item the ProcessRecord method is executed once? if yes, is there a way to find out the current pass number of the ProcessRecord method?
Yes ProcessRecord is executed for each pipeline object. Keep in mind that a single pipeline object could be an array depending on how you define your property that is pipeline bound. I'm not aware of a built-in way to determine the pass number but you can always add an int field to your cmdlet and increment it each time ProcessRecord gets called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.