powershell - cmdlet says parameter cannot be retrieved: expression must be readable -


my cmdlet has get-deal command, receive value 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 passed list of string or other types. if passed object 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 error :

pipeline input cannot processed because default value of parameter 'legalentity' cannot retrieved. exception getting 'legalentity' : expression must readable parameter name: expression

i sure search-deal works fine because

$a = search-deal name  

is working. , giving:

get-deal $a 

returns exact result want.

however

$a | get-deal  

will error out same 1 too.

edit: using

trace-command -name parameterbinding -expression { search-deal jl | get-deal } -pshost 

i found following:

calling beginprocessing  bind pipeline object parameters: [get-deal]  pipeline object type = [system.management.automation.pscustomobject]  restoring pipeline parameter's original values  bind pipeline object parameters: [out-default]  pipeline object type = [system.management.automation.errorrecord]  parameter [inputobject] pipeline input valuefrompipeline no coercion  bind arg [pipeline input cannot processed because default value of parameter 'legalentity' cannot retrieved. exception getting "legalentity": "expression must readable parameter name: expression"]  

so think must wrong pipeline passing objects.

thanks helps!

the way powershell pipeline works prevent kind of scenario. instaed of passing whole list - pass elements 1 one. prevent happening can use unary comma:

, $a | get-deals 

however suggestion (as powershell user): not it, unless have reason. instead, accept/ write single objects. more natural , should spare future user similar griefs have (quite opposite - expect stream of objects returned rather single "bloat" ;) )

also: practice name cmdlets singular noun. if expect more (get-process, get-service, get-childitem...)


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -