BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Why Cmdlets?

Why Cmdlets?

Bookmarks

Jeffrey Snover describes the differences between using Cmdlets and APIs. He concludes with "Cmdlets are designed for Admins at keyboards while APIs are not. Cmdlets are the very heart and soul of PowerShell."

Cmdlets are created by inheriting from the Cmdlet or PSCmdlet base class. Both are implemented by overriding the BeginProcessing, ProcessRecord, and EndProcessing virtual functions.

These classes differ by the amount of PowerShell infrastructure they expose. While Cmdlet is lightweight and can be called from other Cmdlets, PSCmdlet offers access to the PowerShell runtime including environmental variables and session state.

Jeffrey Snover makes his case for Cmdlets by pointing out how they have much better support under PowerShell. Some highlights from his list include:

  • Naming. Cmdlet naming is specific and constrained to allow Admins to successfully make a set of guesses about the world. Cmdlets follow a VERB-NOUN pattern with strong guidelines about the use of Verbs. Guidelines for parameters are also provided. APIs are much less predictable than cmdlets.
  • Tab-Completion. PowerShell provides tab-completion for cmdlets and parameters but not for APIs.
  • Help. Cmdlets provide admin-oriented man-style help. APIs provide developer oriented help.
  • Discoverability. PowerShell provides a number of Admin-friendly ways to discover Cmdlets including Get-Command, Get-Help (both of which support wildcards), See-Also section of HELP.
  • APIs just throw errors whereas Cmdlets draw the distinction between terminating and non-terminating errors. Non-terminating errors support bulk operations better but allowing operations to continue while gathering up all those elements that had issues and making them available as a collection.
    Pipelines. Cmdlets can be written to support PIPELINE input. APIs require the user to do programming to achieve a similar result.

Jeffery also mentions that "In V2 – the gap between Cmdlets and APIs is going to grow MUCH larger. There will be important functions that will only be available to Cmdlets."

 

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • PowerShell Has Grown Up

    by John DeHope,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I last looked at PowerShell when it was still Monad. Wow has a lot changed since then. It has really come of age. After surfing the blog in this article, here are two more blog entries that really blew me away...

    Interact with PowerShell through the CLI...
    blogs.msdn.com/powershell/archive/2007/06/22/ho...

    Talk to an sql server...
    blogs.msdn.com/powershell/archive/2007/06/21/de...

  • Re: PowerShell Has Grown Up

    by Jonathan Allen,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I am glad I was able to bring your attention back to it. And thankyou for the links, I found them quite interesting.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT