My cmdlet has a Get-Deal
command, which will receive value from pipeline:
[Cmdlet(VerbsCommon.Get, "Deal")]
public class GetDealCmdlet : InsightBaseCmdlet
{
private List<Object> _legalentities = new List<Object>();
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true,ValueFromPipelineByPropertyName = true)]
public List<Object> Legalentity { set { _legalentities = value; } }
protected override void ProcessRecord() {...}
}
It works fine if I passed a list of string or other types. However if I passed an object that is created in Search-Deal
:
foreach (...)
{
PSObject dealValue = new PSObject();
dealValue.Properties.Add(new PSNoteProperty(Legalentity,Convert.ToInt32($deal.Properties["LegalEntityID"].Value.ToString())));
dealValue.Properties.Add(new PSNoteProperty("Name",deal.Properties["name"].Value.ToString()));
WriteObject(dealValue);
}
I get an error :
Pipeline input cannot be processed because the default value of parameter 'Legalentity' cannot be retrieved. Exception getting 'Legalentity' : expression must be readable Parameter Name: expression
I am sure that the search-Deal
works fine because
$a = Search-Deal name
is working. And giving:
Get-Deal $a
returns the exact result that I want.
However
$a | Get-Deal
will error out by the same one too.
EDIT:
using
Trace-Command -Name ParameterBinding -Expression { Search-Deal JL | Get-Deal } -PSHost
I found the following:
CALLING BeginProcessing
BIND PIPELINE object to parameters: [Get-Deal]
PIPELINE object TYPE = [System.Management.Automation.PSCustomObject]
RESTORING pipeline parameter's original values
BIND PIPELINE object to parameters: [Out-Default]
PIPELINE object TYPE = [System.Management.Automation.ErrorRecord]
Parameter [InputObject] PIPELINE INPUT ValueFromPipeline NO COERCION
BIND arg [Pipeline input cannot be processed because the default value of parameter 'LegalEntity' cannot be retrieved. Exception getting "LegalEntity": "Expression must be readable Parameter name: expression"]
So I think it must be something wrong with the pipeline passing objects.
Thanks for any helps!