2016-10-14 1 views

答えて

3

それは同じことです。ここで起こっていることは、パラメータが(時には、通常は)名前付きか位置的に使用できることです。

この場合、まだ-Promptパラメータの値を指定していますが、具体的に名前で参照しているわけではありません。これが起こっていることを確認するには

ファンシーな方法はTrace-Commandコマンドレットである:

Trace-Command -Name ParameterBinding -Expression { Read-Host "Hello" } -PSHost 

出力:

DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Read-Host] 
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Read-Host] 
DEBUG: ParameterBinding Information: 0 : BIND REMAININGARGUMENTS cmd line args to param: [Prompt] 
DEBUG: ParameterBinding Information: 0 :  BIND arg [System.Collections.Generic.List`1[System.Object]] to parameter 
[Prompt] 
DEBUG: ParameterBinding Information: 0 :   COERCE arg to [System.Object] 
DEBUG: ParameterBinding Information: 0 :    Parameter and arg types the same, no coercion is needed. 
DEBUG: ParameterBinding Information: 0 :   BIND arg [System.Collections.Generic.List`1[System.Object]] to param 
[Prompt] SUCCESSFUL 
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Read-Host] 
DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing 
Hello: hi 
DEBUG: ParameterBinding Information: 0 : CALLING EndProcessing 
hi 
2

Read-Hostのヘルプテキストは、構文図を示します:

PS> help Read-Host 

Read-Host [[-Prompt] <Object>] [-AsSecureString] 
      [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] 
      [-InformationVariable <System.Stringr>] [<CommonParameters>] 

... 

これらの構文図を読むべきかの完全な説明は、(help about_Command_Syntaxを参照してください。)内蔵のヘルプから入手可能である。適切な部分は次のとおりです。

の場合はそう
-- Brackets ([ ]) indicate optional items. A parameter and its value can be 
    optional, or the name of a required parameter can be optional. 

-Prompt引数の場合、パラメータの両方の値はオプションです。

+0

++偉大な教師と人間の魚の答え。 – mklement0

関連する問題