此示例演示如何编写可用于在程序集中注册所有 cmdlet 和 Windows PowerShell 提供程序的 Windows PowerShell 管理单元。
使用此类型的管理单元,不选择要注册的 cmdlet 和提供程序。 若要编写允许你选择已注册的内容的管理单元,请参阅 编写自定义 Windows PowerShell 管理单元。
编写 Windows PowerShell 管理单元
添加 RunInstallerAttribute 属性。
创建派生自 System.Management.Automation.PSSnapIn 类的公共类。
在此示例中,类名为“GetProcPSSnapIn01”。
为管理单元的名称添加公共属性(必需)。 命名管理单元时, 请勿使用以下任何字符:
#
、.
、,
、(
、)
、{
、}
、[
、]
、&
、-
、/
、\
、$
、;
、:
、"
、'
、<
、>
、|
、?
、@
、`
、*
在此示例中,管理单元的名称为“GetProcPSSnapIn01”。
为管理单元的供应商添加公共属性(必需)。
在此示例中,供应商为“Microsoft”。
为管理单元的供应商资源添加公共属性(可选)。
在此示例中,供应商资源为“GetProcPSSnapIn01,Microsoft”。
为管理单元的说明添加公共属性(必需)。
在此示例中,说明为“这是注册 Get-Proc cmdlet 的 Windows PowerShell 管理单元”。
为管理单元的说明资源添加公共属性(可选)。
在此示例中,供应商资源为“GetProcPSSnapIn01,这是注册 Get-Proc cmdlet 的 Windows PowerShell 管理单元”。
示例
此示例演示如何编写可用于在 Windows PowerShell shell 中注册 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.";
}
}
}