相关疑难解决方法(0)

Powershell将object []传递给函数

有人可以指点我一个资源,可以告诉我如何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)

powershell

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1