我有一个名为Get-Organization
的cmdlet,它返回以下作为返回类型
public class OrgModel
{
public string OrgName {get;set;}
}
[Cmdlet(VerbsCommon.Get, "Organization")]
[OutputType(typeof(OrgModel))]
public GetOrganizationCmdlet : PSCmdlet
{
[Alias("OrgName")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "The orgname.")]
string Name{get;set}
...
}
我有另一个名为Department
的cmdlet,它返回一个模型DepartmentModel
。 Get-Department -OrgName <somename>
会返回Orgname
内的所有部门。 cmdlet定义如下。
[Cmdlet(VerbsCommon.Get, "Department")]
public GetDepartmentCmdlet : PSCmdlet
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "The org name.")]
[ValidateNotNullOrEmpty]
string OrgName {get;set}
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 1, HelpMessage = "Optional. The department name.")]
string Name{get;set}
...
}
加载模块后,一切都按预期工作。它破碎的地方是管道。以下返回错误
Get-Organization -Name <somename> | Get-Department
正如您所看到的,返回类型OrgModel
有一个名为OrgName
的属性,该属性应自动绑定到Get-Department
参数OrgName
,但它不是,并且给出了以下内容错误:
C:\WINDOWS\system32> Get-Organization -Name contoso | Get-Department
Get-Department : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:44
+ ... et-Organization -Name contoso | Get-Department
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (OrgModel:PSObject) [Get-Department], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,GetDepartment
有什么想法吗?
答案 0 :(得分:0)
使用@PeterSerAl提到的命令,我注意到返回时间被错误地设置为集合。
修复后可以正常工作。
由于