입력 처리 메서드를 재정의하는 방법
다음 예제는 cmdlet 내에서 입력 처리 메서드를 덮어쓰는 방법을 보여줍니다. 이러한 메서드는 다음 작업을 수행하는 데 사용됩니다.
System.Management.Automation.Cmdlet.BeginProcessing 메서드는 cmdlet에서 처리하는 모든 개체에 유효한 일회성 시작 작업을 수행하는 데 사용됩니다. Windows PowerShell 런타임은 이 메서드를 한 번만 호출합니다.
System.Management.Automation.Cmdlet.ProcessRecord 메서드는 cmdlet에 전달된 개체를 처리하는 데 사용됩니다. Windows PowerShell 런타임은 cmdlet에 전달된 각 개체에 대해 이 메서드를 호출합니다.
System.Management.Automation.Cmdlet.EndProcessing 메서드는 일회성 후 처리 작업을 수행하는 데 사용됩니다. Windows PowerShell 런타임은 이 메서드를 한 번만 호출합니다.
BeginProcessing 메서드를 재정의하려면
- System.Management.Automation.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 메서드를 재정의하려면
- System.Management.Automation.Cmdlet.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 메서드를 재정의하려면
- System.Management.Automation.Cmdlet.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 작성)
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기