Windows PowerShell スナップインを記述する

この例では、アセンブリ内のすべてのコマンドレットと Windows PowerShell プロバイダーを登録するために使用できる Windows PowerShell スナップインを記述する方法を示します。

この種類のスナップインでは、登録するコマンドレットとプロバイダーは選択しません。 登録内容を選択できるスナップインを作成するには、「カスタム Windows PowerShell スナップインを作成する」を参照してください。

Windows PowerShell スナップインを記述する

  1. Runインストーラ属性属性を追加します。

  2. Add-pssnapinクラスから派生するパブリッククラスを作成します。

    この例では、クラス名は "GetProcPSSnapIn01" です。

  3. スナップインの名前のパブリックプロパティを追加します (必須)。 スナップインに名前を付ける場合、 # 、、 . , 、、 () { } [ ] & - / \ $ ; : " ' < > | ? @ 、、、 ` 、、、、、、、、、、、、、、、、、、、、、、、、 *

    この例では、スナップインの名前は "GetProcPSSnapIn01" です。

  4. スナップインのベンダのパブリックプロパティを追加します (必須)。

    この例では、ベンダーは "Microsoft" です。

  5. スナップインのベンダリソースのパブリックプロパティを追加します (省略可能)。

    この例では、vendor リソースは "GetProcPSSnapIn01, Microsoft" です。

  6. スナップインの説明のパブリックプロパティを追加します (必須)。

    この例では、説明は "this is a Windows PowerShell スナップインで、get proc cmdlet" を登録します。

  7. スナップインの説明リソースのパブリックプロパティを追加します (省略可能)。

    この例では、ベンダリソースは "GetProcPSSnapIn01, this は、get proc cmdlet" を登録する Windows PowerShell スナップインです。

この例では、Windows PowerShell シェルで Get-Proc コマンドレットを登録するために使用できる Windows PowerShell スナップインを記述する方法を示します。 この例では、完全なアセンブリには GetProcPSSnapIn01 スナップインクラスとコマンドレットクラスのみが含まれることに注意してください Get-Proc

[RunInstaller(true)]
public class GetProcPSSnapIn01 : PSSnapIn
{
  /// <summary>
  /// Create an instance of the GetProcPSSnapIn01 class.
  /// </summary>
  public GetProcPSSnapIn01()
         : base()
  {
  }

  /// <summary>
  /// Specify the name of the PowerShell snap-in.
  /// </summary>
  public override string Name
  {
    get
    {
      return "GetProcPSSnapIn01";
    }
  }

  /// <summary>
  /// Specify the vendor for the PowerShell snap-in.
  /// </summary>
  public override string Vendor
  {
    get
    {
      return "Microsoft";
    }
  }

  /// <summary>
  /// Specify the localization resource information for the vendor.
  /// Use the format: resourceBaseName,VendorName.
  /// </summary>
  public override string VendorResource
  {
    get
    {
      return "GetProcPSSnapIn01,Microsoft";
    }
  }

  /// <summary>
  /// Specify a description of the PowerShell snap-in.
  /// </summary>
  public override string Description
  {
    get
    {
      return "This is a PowerShell snap-in that includes the get-proc cmdlet.";
    }
  }

  /// <summary>
  /// Specify the localization resource information for the description.
  /// Use the format: resourceBaseName,Description.
  /// </summary>
  public override string DescriptionResource
  {
    get
    {
      return "GetProcPSSnapIn01,This is a PowerShell snap-in that includes the get-proc cmdlet.";
    }
  }
}

参照

コマンドレット、プロバイダー、およびホストアプリケーションを登録する方法

Windows PowerShell シェル SDK