次の方法で共有


Windows PowerShell スナップインの作成

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

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

Windows PowerShell スナップインの作成

  1. RunInstallerAttribute 属性を追加します。

  2. System.Management.Automation.PSSnapIn クラスから派生するパブリック クラスを作成します。

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

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

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

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

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

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

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

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

    この例では、「これは、Get-Proc コマンドレットを登録する Windows PowerShell スナップインです」という説明です。

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

    この例では、ベンダー リソースは "GetProcPSSnapIn01,This is a Windows PowerShell snap-in that registers the Get-Proc cmdlet" です。

この例では、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