Powershell将object []传递给函数

Zac*_*Zac 9 powershell

有人可以指点我一个资源,可以告诉我如何Object[]在一个powershell函数中传入一个参数?这两个函数都是Cmdlet,它们正在正确导出,但我$Return在第二个函数中看不到该对象.

需要这样的东西吗?https://msdn.microsoft.com/en-us/library/system.management.automation.parameterattribute.valuefrompipeline(v=vs.85).aspx

# Within PowerShell code

$Return = My-Function -Param "value" # $Return is of type Object[]
$ModifiedReturn = My-SecondFunction -Input $Return
Run Code Online (Sandbox Code Playgroud)

这是我的功能定义

function My-SecondFunction
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True)]
        [Object[]]$Input
    )
    begin {}
    process
    {
        Write-Host "test: $Input" # Does not return anything
    }
    end {}
}
Run Code Online (Sandbox Code Playgroud)

bri*_*ist 8

$Input自动变量的名称.使用其他名称.

我建议$InputObject这是常用的,因此它有一个很好理解的含义,但通常这意味着你也接受管道输入.

当然,如果有一个更具描述性的名称,你应该使用它.

我已经在PowerShell github项目上提交了这个问题,建议Set-StrictMode修改它以检查自动变量赋值.