此範例示範如何撰寫可用來註冊元件中所有 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 殼層中註冊 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.";
}
}
}