2017-01-27 16 views
4

誰かがpowershell関数内でパラメータとしてObject[]を渡す方法を教えてくれるリソースを指摘できますか?これらの関数は両方ともコマンドレットであり、正しくエクスポートされていますが、私の2番目の関数では$Returnオブジェクトが表示されません。powershellはオブジェクト[]を関数に渡します

このようなものが必要ですか?これは私の関数definiton

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

答えて

5

$Inputある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 

automatic variableの名前です。別の名前を使用してください。

一般的な意味で使用されているように、私は$InputObjectを推奨していますが、これはよく理解されていますが、通常はパイプライン入力も受け入れます。

もちろん、このパラメータを説明する名前がある場合は、それを使用する必要があります。

I have submitted this issue on the PowerShell github project suggesting that Set-StrictMode be modified to check for automatic variable assignment

関連する問題