次の方法で共有


入力処理メソッドをオーバーライドする方法

これらの例は、コマンドレット内の入力処理メソッドを上書きする方法を示しています。 これらのメソッドは、次の操作を実行するために使用されます。

  • コマンドレットによって処理されるすべてのオブジェクトに対して有効な1回限りのスタートアップ操作を実行するには、 このメソッドを 使用します。 Windows PowerShell ランタイムは、このメソッドを1回だけ呼び出します。

  • コマンドレットに渡されたオブジェクトを処理するには、.................. ProcessRecord メソッドを使用します。 Windows PowerShell ランタイムは、コマンドレットに渡された各オブジェクトに対してこのメソッドを呼び出します。

  • 1回限りの処理操作を実行するには、system.servicemodel メソッドを 使用します 。 Windows PowerShell ランタイムは、このメソッドを1回だけ呼び出します。

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(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.object メソッドの保護されたオーバーライドを宣言します。

次のクラスは、サンプルを出力します。 このクラスを使用するには、コマンドレット属性の動詞と名詞を変更し、新しい動詞と名詞を反映するようにクラスの名前を変更します。次に、必要な機能を、 システム のオーバーライドメソッドのオーバーライドに追加します。

[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.");
  }
}

参照

システムの管理... コマンドレット

システムの管理... コマンドレット

システムの管理....................

Windows PowerShell コマンドレットの記述