Over a million developers have joined DZone.

Windows Powershell Cmdlet - Creation And Registration

DZone's Guide to

Windows Powershell Cmdlet - Creation And Registration

· ·
Free Resource
Adapted from "Windows PowerShell Programmer's Guide", at http://windowssdk.msdn.microsoft.com/en-us/library/ms714674.aspx

// Reference added to "System.Management.Automation.dll" in "C:\Program Files\Windows PowerShell\v1.0":
using System.Management.Automation;

namespace CmdletTest
    [Cmdlet(VerbsCommon.Get, "Hjnntaao")]
    public class GetHjnntaaoCommand : Cmdlet
        // BeginProcessing - pre-processing/set-up

        // If accepts pipeline input, must override ProcessRecord and, optionally, EndProcessing

        // If does not take pipline input, should override EndProcessing

        // Cmdlets should never call WriteLine, or equivalent.
        protected override void ProcessRecord()
            Process[] processes = Process.GetProcesses();


       This method of registering the Cmdlet with PowerShell extends the shell using snap-ins. This should
       be the default way of registering Cmdlets. The other way, registering with a custom shell,
       should only be used to create executable files.
       To install:
       1) installutil CmdletTest.dll
       2) Verify the snap in is in the list of registered snap-ins awaiting to be loaded by
          running "get-pssnapin -registered"
       3) Add the snap in to the shell by using "add-pssnapin "GetHjnntaaoPSSSnapIn01"
    public class GetHjnntaaoPSSnapIn01 : PSSnapIn
        public override string Name
            get { return "GetHjnntaaoPSSnapIn01"; }

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

        public override string Description
            get { return "Hjnntaao's Cmdlet"; }


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}