cmdlets vs functions

This topic contains 2 replies, has 3 voices, and was last updated by  Don Jones 3 years, 2 months ago.

  • Author
    Posts
  • #15761

    Bojan Zivkovic
    Participant

    Hi, I am learning PowerShell by using CBT PowerShell Ultimate Training by Don Jones. After covering first 62 lessons (nuggets) everything so far is pretty clear because Don explained in details all covered areas. One thing comes to my mind and that is the difference between cmdlet and function. Don covered basic and advanced functions that can accept input from pipeline and by passing parameter names without pipeline, which is also the case for cmdlets written by Microsoft. Is writing cmdlets obsolete, are functions the best way to write custom code and then putting them into the custom module? If not how to write custom cmdlet with the same level of functionality like advanced functions?

  • #15763

    Matt McNabb
    Participant

    Here's a link to an overview of writing a Powershell cmdlet:
    http://msdn.microsoft.com/en-us/library/dd878294%28v=vs.85%29.aspx

    Basically a true Powershell cmdlet is written in a .NET programming language, typically C#, and compiled – so in a way it's a real application. An advanced function is written in Powershell (although you could include some custom C# code) and is not compiled. There are probably performance benefits to implementing a compiled cmdlet rather than an advanced function but the functions exist for us average joe admins who aren't real programmers to be able to develop and share our own tools.

    This is probably not the most eloquent description so I'll leave the nitty-gritty details to those who know more about the developer side of Powershell and .NET.

  • #15765

    Don Jones
    Keymaster

    That's about right. A cmdlet actually sets the baseline; it can do "everything." Until we got advanced functions, script was more limited.

You must be logged in to reply to this topic.