이 예제에서는 특정 cmdlet을 등록하는 Windows PowerShell 스냅인을 작성하는 방법을 보여 줍니다.
이 유형의 스냅인을 사용하면 등록할 cmdlet, 공급자, 형식 또는 형식을 지정합니다. 어셈블리의 모든 cmdlet 및 공급자를 등록하는 스냅인을 작성하는 방법에 대한 자세한 내용은 Windows PowerShell 스냅인작성을 참조하세요.
특정 cmdlet을 등록하는 Windows PowerShell 스냅인을 작성하려면
RunInstallerAttribute 특성을 추가합니다.
System.Management.Automation.CustomPSSnapIn 클래스에서 파생되는 공용 클래스를 만듭니다.
이 예제에서 클래스 이름은 "CustomPSSnapinTest"입니다.
스냅인 이름에 대한 public 속성을 추가합니다(필수). 스냅인의 이름을 지정할 때
#
,.
,,
,(
,)
,{
,}
,[
,]
,&
,-
,/
중 어떤 문자도 사용하지 마세요. ,\
,$
,;
,:
,"
,'
,<
,>
,|
,?
,@
,`
,*
이 예제에서 스냅인의 이름은 "CustomPSSnapInTest"입니다.
스냅인(필수)의 공급업체에 대한 공용 속성을 추가합니다.
이 예제에서 공급업체는 "Microsoft"입니다.
스냅인의 공급업체 리소스에 대한 공용 속성을 추가합니다(선택 사항).
이 예제에서 공급업체 리소스는 "CustomPSSnapInTest,Microsoft"입니다.
스냅인(필수)에 대한 설명에 대한 public 속성을 추가합니다.
이 예제에서 설명은 "
Test-HelloWorld
및Test-CustomSnapinTest
cmdlet을 포함하는 사용자 지정 Windows PowerShell 스냅인입니다."스냅인의 설명 리소스에 대한 public 속성을 추가합니다(선택 사항).
이 예제에서 공급업체 리소스는 다음과 같습니다.
CustomPSSnapInTest, Test-HelloWorld 및 Test-CustomSnapinTest cmdlet"을 포함하는 사용자 지정 Windows PowerShell 스냅인입니다.
System.Management.Automation.Runspaces.CmdletConfigurationEntry 클래스를 사용하여 사용자 지정 스냅인(선택 사항)에 속하는 cmdlet을 지정합니다. 여기에 추가된 정보에는 cmdlet의 이름, .NET 형식 및 cmdlet 도움말 파일 이름(cmdlet 도움말 파일 이름의 형식은
name.dll-help.xml
)이 포함됩니다.이 예제에서는 Test-HelloWorld 및 TestCustomSnapinTest cmdlet을 추가합니다.
사용자 지정 스냅인에 속하는 공급자를 지정합니다(선택 사항).
이 예제에서는 공급자를 지정하지 않습니다.
사용자 지정 스냅인에 속하는 형식을 지정합니다(선택 사항).
이 예제에서는 형식을 지정하지 않습니다.
사용자 지정 스냅인에 속하는 형식을 지정합니다(선택 사항).
이 예제에서는 형식을 지정하지 않습니다.
예시
이 예제에서는 Test-HelloWorld
및 Test-CustomSnapinTest
cmdlet을 등록하는 데 사용할 수 있는 사용자 지정 Windows PowerShell 스냅인을 작성하는 방법을 보여 줍니다. 이 예제에서 전체 어셈블리에는 이 스냅인에 의해 등록되지 않는 다른 cmdlet 및 공급자가 포함될 수 있습니다.
[RunInstaller(true)]
public class CustomPSSnapinTest : CustomPSSnapIn
{
/// <summary>
/// Creates an instance of CustomPSSnapInTest class.
/// </summary>
public CustomPSSnapinTest()
: base()
{
}
/// <summary>
/// Specify the name of the custom PowerShell snap-in.
/// </summary>
public override string Name
{
get
{
return "CustomPSSnapInTest";
}
}
/// <summary>
/// Specify the vendor for the custom PowerShell snap-in.
/// </summary>
public override string Vendor
{
get
{
return "Microsoft";
}
}
/// <summary>
/// Specify the localization resource information for the vendor.
/// Use the format: resourceBaseName,resourceName.
/// </summary>
public override string VendorResource
{
get
{
return "CustomPSSnapInTest,Microsoft";
}
}
/// <summary>
/// Specify a description of the custom PowerShell snap-in.
/// </summary>
public override string Description
{
get
{
return "This is a custom PowerShell snap-in that includes the Test-HelloWorld and Test-CustomSnapinTest cmdlets.";
}
}
/// <summary>
/// Specify the localization resource information for the description.
/// Use the format: resourceBaseName,Description.
/// </summary>
public override string DescriptionResource
{
get
{
return "CustomPSSnapInTest,This is a custom PowerShell snap-in that includes the Test-HelloWorld and Test-CustomSnapinTest cmdlets.";
}
}
/// <summary>
/// Specify the cmdlets that belong to this custom PowerShell snap-in.
/// </summary>
private Collection<CmdletConfigurationEntry> _cmdlets;
public override Collection<CmdletConfigurationEntry> Cmdlets
{
get
{
if (_cmdlets == null)
{
_cmdlets = new Collection<CmdletConfigurationEntry>();
_cmdlets.Add(new CmdletConfigurationEntry("test-customsnapintest", typeof(TestCustomSnapinTest), "TestCmdletHelp.dll-help.xml"));
_cmdlets.Add(new CmdletConfigurationEntry("test-helloworld", typeof(TestHelloWorld), "HelloWorldHelp.dll-help.xml"));
}
return _cmdlets;
}
}
/// <summary>
/// Specify the providers that belong to this custom PowerShell snap-in.
/// </summary>
private Collection<ProviderConfigurationEntry> _providers;
public override Collection<ProviderConfigurationEntry> Providers
{
get
{
if (_providers == null)
{
_providers = new Collection<ProviderConfigurationEntry>();
}
return _providers;
}
}
/// <summary>
/// Specify the types that belong to this custom PowerShell snap-in.
/// </summary>
private Collection<TypeConfigurationEntry> _types;
public override Collection<TypeConfigurationEntry> Types
{
get
{
if (_types == null)
{
_types = new Collection<TypeConfigurationEntry>();
}
return _types;
}
}
/// <summary>
/// Specify the formats that belong to this custom PowerShell snap-in.
/// </summary>
private Collection<FormatConfigurationEntry> _formats;
public override Collection<FormatConfigurationEntry> Formats
{
get
{
if (_formats == null)
{
_formats = new Collection<FormatConfigurationEntry>();
}
return _formats;
}
}
}
스냅인 등록에 대한 자세한 내용은 Windows PowerShell 프로그래머 가이드 Cmdlet, 공급자 및 호스트 애플리케이션 등록하는 방법을 참조하세요.
또한 참조하십시오
Cmdlet, 공급자 및 호스트 애플리케이션 등록하는 방법
PowerShell