Vijay
Vijay

Reputation: 167

C# PowerShell pipeline input flag/property

I am creating PowerShell cmdlets in C# by extending the PSCmdlet class. I need to use the same parameter for pipeline input and normal parameter input. Eg

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

Here the Connection parameter can take both pipeline input

$connectionValue | Cmdlet-Name

and also normal parameter using

Cmdlet-Name -Connection $connectionValue

Is there a way in C# by which I can find out if the parameter value is pipelined to the cmdlet or provided using -Connection? In PowerShell this can be done by checking if $input is empty or not. Is there any parameter property that can indicate the input type?

Upvotes: 2

Views: 634

Answers (1)

rerun
rerun

Reputation: 25505

You can check by seeing if its set when beginprocessing is called or if it only is set during process record. Non pipeline properties are set before begin processing is called.

Upvotes: 2

Related Questions