다음을 통해 공유


입력 처리 메서드를 재정의하는 방법

다음 예제는 cmdlet 내에서 입력 처리 메서드를 덮어쓰는 방법을 보여줍니다. 이러한 메서드는 다음 작업을 수행하는 데 사용됩니다.

BeginProcessing 메서드를 재정의하려면

다음 클래스는 샘플 메시지를 출력합니다. 이 클래스를 사용하려면 Cmdlet 특성에서 동사와 명사를 변경하고 새 동사와 명사를 반영하도록 클래스 이름을 변경한 다음 System.Management.Automation.Cmdlet.BeginProcessing 메서드의 재정의에 필요한 기능을 추가합니다.

[Cmdlet(VerbsDiagnostic.Test, "BeginProcessingClass")]
public class TestBeginProcessingClassTemplate : Cmdlet
{
  // Override the BeginProcessing method to add preprocessing
  //operations to the cmdlet.
  protected override void BeginProcessing()
  {
    // Replace the WriteObject method with the logic required
    // by your cmdlet. It is used here to generate the following
    // output:
    // "This is a test of the BeginProcessing template."
    WriteObject("This is a test of the BeginProcessing template.");
  }
}

ProcessRecord 메서드를 재정의하려면

다음 클래스는 샘플 메시지를 출력합니다. 이 클래스를 사용하려면 Cmdlet 특성에서 동사와 명사를 변경하고 새 동사와 명사를 반영하도록 클래스 이름을 변경한 다음 System.Management.Automation.Cmdlet.ProcessRecord 메서드의 재정의에 필요한 기능을 추가합니다.

[Cmdlet(VerbsDiagnostic.Test, "ProcessRecordClass")]
public class TestProcessRecordClassTemplate : Cmdlet
{
    // Override the ProcessRecord method to add processing
    //operations to the cmdlet.
    protected override void ProcessRecord()
    {
        // Replace the WriteObject method with the logic required
        // by your cmdlet. It is used here to generate the following
        // output:
        // "This is a test of the ProcessRecord template."
        WriteObject("This is a test of the ProcessRecord template.");
    }
}

EndProcessing 메서드를 재정의하려면

다음 클래스는 샘플을 인쇄합니다. 이 클래스를 사용하려면 Cmdlet 특성에서 동사와 명사를 변경하고 새 동사와 명사를 반영하도록 클래스 이름을 변경한 다음 System.Management.Automation.Cmdlet.EndProcessing 메서드의 재정의에 필요한 기능을 추가합니다.

[Cmdlet(VerbsDiagnostic.Test, "EndProcessingClass")]
public class TestEndProcessingClassTemplate : Cmdlet
{
  // Override the EndProcessing method to add postprocessing
  //operations to the cmdlet.
  protected override void EndProcessing()
  {
    // Replace the WriteObject method with the logic required
    // by your cmdlet. It is used here to generate the following
    // output:
    // "This is a test of the BeginProcessing template."
    WriteObject("This is a test of the EndProcessing template.");
  }
}

참고 항목

System.Management.Automation.Cmdlet.BeginProcessing

System.Management.Automation.Cmdlet.EndProcessing

System.Management.Automation.Cmdlet.ProcessRecord

Writing a Windows PowerShell Cmdlet(Windows PowerShell Cmdlet 작성)