Pass the [] object to a function in PowerShell

Is there a resource on how to pass Object[]as a parameter to a PowerShell function?

Both of these functions are cmdlets, and they are exported correctly, but I do not see the object $Returnin the second function.

Do I need something like the following?

ParameterAttribute.ValueFromPipeline Property (System.Management.Automation)

# Within PowerShell code

$Return = My-Function -Param "value" # $Return is of type Object[]
$ModifiedReturn = My-SecondFunction -Input $Return

Where is my function definition:

function My-SecondFunction
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True)]
        [Object[]]$Input
    )
    begin {}
    process
    {
        Write-Host "test: $Input" # Does not return anything
    }
    end {}
}
+8
source share
1 answer

$Inputis the name of the automatic variable . Use a different name.

I recommend $InputObjectit because it is widely used, so it has a clear meaning, but usually it means that you also accept the pipeline input.

, , , .

PowerShell GitHub, Set-StrictMode .

+8

Source: https://habr.com/ru/post/1668031/


All Articles