2013-10-31 9 views
0

이 cmdlet을 고려 (using이 제거) :파워 쉘 : parametersets이 하나 필요하거나 다른

다음
public class Foo : Cmdlet 
{ 
    [Parameter(Mandatory = true, ParameterSetName = "Foo"] 
    public string A { get; set; } 

    [Parameter(Mandatory = true, ParameterSetName = "Bar"] 
    public string B { get; set; } 

    [Parameter(Mandatory = true, ParameterSetName = "Bar"] 
    public string C { get; set; } 

    protected override void ProcessRecord() 
    { 
     /* magic goes here */ 
    } 
} 

이제이 cmdlet을 실행할 수있는 방법입니다 같이

# like this 
Foo 

# or 
Foo -A "test" 

# or 
Foo -B "test" -C "test" 

을 갖고, 그리고 B는 작동하지 않으며 B 만 사용하지도 않습니다 (C가 필요함).

그래도 Foo을 입력하여 Cmdlet을 실행할 수 없도록 방지하고 싶습니다. 코드에서 확인할 수 있지만 Powershell은 너무 굉장하므로 런타임을 통해 강제 적용 할 수 있습니까?

당신은 CmdletAttribute 속성의 DefaultParameterSetName 재산의 방법에 의해 명명 된 매개 변수 세트에 기본으로 PowerShell을 지시 할 수있다

답변

3

:

[Cmdlet("Foo", "Bar", DefaultParameterSetName = "Foo")] 
public class Foo : Cmdlet 
{ 
    // ... 
}