パラメータ群が複数ある場合の調べ方(1)

Cmdletのパラメータを調べる

Cmdletは「System.Management.Automation.CmdletInfo」で定義されます。

MSH C:\> (get-command new-object).getType().fullname
System.Management.Automation.CmdletInfo

Cmdletのパラメータ群は「ParameterSetInfo」で定義され、「CmdletInfo」は「ParameterSetInfo」のコレクションである「ParameterSets」を保持します。


Cmdletは複数のパラメータ群を持つことができます。例えば「new-object」がそうです。
以下のコマンドで分かるように「write-host」のパラメータ群は1つ、「new-object」のパラメータ群は2つです。

MSH C:\> (get-command write-host).ParameterSets.Count
1
MSH C:\> (get-command new-object).ParameterSets.Count
2

2つのパラメータ群はそれぞれ「Net」「Com」という名前です。
.NETオブジェクト、COMオブジェクトを生成する際のパラメータ群になります。

MSH C:\> $((gcm new-object).ParameterSets)[0].Name
Net
MSH C:\> $((gcm new-object).ParameterSets)[1].Name
Com


続く・・・