powershell定義命令(四)

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using System.Threading.Tasks;

namespace PSBook.Chapter2
{


    [Cmdlet(VerbsCommunications.Write, "Hello")]
    class SayHello : Cmdlet
    {
        protected override void ProcessRecord()
        {
            WriteObject("Hello,world");

        }
    }


    /// <summary>
    /// 定義module的基本信息,必須實現PSSnapIn
    /// 指定在安裝程序集時是否應調用 Visual Studio 自定義操作安裝程序或 Installutil.exe
    /// </summary>
    /// 


    [RunInstaller(true)]
    public class PSBookChapter2MySnapIn:CustomPSSnapIn
    {
         private  Collection<CmdletConfigurationEntry> cmdlets;

         public override Collection<CmdletConfigurationEntry> Cmdlets
         {

             get
             {
                 if (cmdlets == null)
                 {
                     cmdlets = new Collection<CmdletConfigurationEntry>();
                     cmdlets.Add(
                         new CmdletConfigurationEntry("Say-Hello", typeof(SayHello), null)
                     );
                 }
                 return cmdlets;
             }
         }

         public override string Description
         {
             get { return "This is a sample powershell snap-in"; }
         }

         public override string Name
         {
             //該名稱在生成一個以snap-in 的Nanme屬性爲鍵名的註冊表鍵值
             get { return "wiley.PSProfessional.Chapter"; }
         }

         public override string Vendor
         {
             get { return "wiley"; }
         }


         private Collection<ProviderConfigurationEntry> provides;
         public override Collection<ProviderConfigurationEntry> Providers
         {
             get
             {
                 if (provides == null)
                 {
                     provides = new Collection<ProviderConfigurationEntry>();
                     
                 }
                 return provides;
             }
         }

         private Collection<TypeConfigurationEntry> types;
         public override Collection<TypeConfigurationEntry> Types
         {
             get
             {
                 if (types == null)
                 {
                     types = new Collection<TypeConfigurationEntry>();
                 }
                 return types;
             }
         }

         private Collection<FormatConfigurationEntry> formats;
         public override Collection<FormatConfigurationEntry> Formats
         {
             get
             {
                 if(formats==null){
                     formats = new Collection<FormatConfigurationEntry>();
                 }
                 return formats;
             }
         }

        
            

        //public override string Description
        //{
        //    get { return "This is a sample powershell snap-in"; }
        //}

        //public override string Name
        //{
        //    //該名稱在生成一個以snap-in 的Nanme屬性爲鍵名的註冊表鍵值
        //    get { return "wiley.PSProfessional.Chapter2"; }
        //}

        //public override string Vendor
        //{
        //    get {  return "wiley"; }
        //}
    }
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章