Share via


Cómo invalidar los métodos de procesamiento de entrada

En estos ejemplos se muestra cómo sobrescribir los métodos de procesamiento de entrada dentro de un cmdlet. Estos métodos se usan para realizar las siguientes operaciones:

Para invalidar el método BeginProcessing

La clase siguiente imprime un mensaje de ejemplo. Para usar esta clase, cambie el verbo y el sustantivo en el atributo Cmdlet, cambie el nombre de la clase para reflejar el nuevo verbo y el nombre y, a continuación, agregue la funcionalidad que necesita a la invalidación del método 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.");
  }
}

Para invalidar el método ProcessRecord

La clase siguiente imprime un mensaje de ejemplo. Para usar esta clase, cambie el verbo y el sustantivo en el atributo Cmdlet, cambie el nombre de la clase para reflejar el nuevo verbo y el sustantivo y, a continuación, agregue la funcionalidad que necesita a la invalidación del método 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.");
    }
}

Para invalidar el método EndProcessing

La clase siguiente imprime un ejemplo. Para usar esta clase, cambie el verbo y el sustantivo en el atributo Cmdlet, cambie el nombre de la clase para reflejar el nuevo verbo y el nombre y, a continuación, agregue la funcionalidad que necesita a la invalidación del método 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.");
  }
}

Consulte también

System.Management.Automation.Cmdlet.BeginProcessing

System.Management.Automation.Cmdlet.EndProcessing

System.Management.Automation.Cmdlet.ProcessRecord

Escribir un cmdlet de Windows PowerShell