다음을 통해 공유


Windows PowerShell 스냅인 작성

이 예제에서는 모든 cmdlet 및 Windows PowerShell 공급자를 어셈블리에 등록하는 데 사용할 수 있는 Windows PowerShell 스냅인을 작성하는 방법을 보여 줍니다.

이 유형의 스냅인에서는 등록할 cmdlet 및 공급자를 선택하지 않습니다. 등록된 항목을 선택할 수 있는 스냅인을 작성하려면 사용자 지정 Windows PowerShell 스냅인작성을 참조하세요.

Windows PowerShell 스냅인 작성

  1. RunInstallerAttribute 특성을 추가합니다.

  2. System.Management.Automation.PSSnapIn 클래스에서 파생되는 공용 클래스를 만듭니다.

    이 예제에서 클래스 이름은 "GetProcPSSnapIn01"입니다.

  3. 스냅인 이름에 대한 public 속성을 추가합니다(필수). 스냅인의 이름을 지정할 때 #, ., ,, (, ), {, }, [, ], &, -, /중 어떤 문자도 사용하지 마세요. , \, $, ;, :, ", ', <, >, |, ?, @, `, *

    이 예제에서 스냅인의 이름은 "GetProcPSSnapIn01"입니다.

  4. 스냅인(필수)의 공급업체에 대한 공용 속성을 추가합니다.

    이 예제에서 공급업체는 "Microsoft"입니다.

  5. 스냅인의 공급업체 리소스에 대한 공용 속성을 추가합니다(선택 사항).

    이 예제에서 공급업체 리소스는 "GetProcPSSnapIn01,Microsoft"입니다.

  6. 스냅인(필수)에 대한 설명에 대한 public 속성을 추가합니다.

    이 예제에서 설명은 "Get-Proc cmdlet을 등록하는 Windows PowerShell 스냅인입니다."입니다.

  7. 스냅인의 설명 리소스에 대한 public 속성을 추가합니다(선택 사항).

    이 예제에서 공급업체 리소스는 "GetProcPSSnapIn01,이 Get-Proc cmdlet을 등록하는 Windows PowerShell 스냅인입니다."입니다.

예시

이 예제에서는 Windows PowerShell 셸에서 Get-Proc cmdlet을 등록하는 데 사용할 수 있는 Windows PowerShell 스냅인을 작성하는 방법을 보여 줍니다. 이 예제에서 전체 어셈블리에는 GetProcPSSnapIn01 스냅인 클래스와 Get-Proc cmdlet 클래스만 포함됩니다.

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

또한 참조하십시오

Cmdlet, 공급자 및 호스트 애플리케이션 등록하는 방법

windows PowerShell Shell SDK