cmdlets vs functions

Welcome Forums General PowerShell Q&A cmdlets vs functions

This topic contains 2 replies, has 3 voices, and was last updated by

5 years, 4 months ago.

  • Author
  • #15761

    Topics: 36
    Replies: 42
    Points: 42
    Rank: Member

    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

    Topics: 1
    Replies: 92
    Points: 2
    Rank: Member

    Here's a link to an overview of writing a Powershell cmdlet:

    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

    Topics: 13
    Replies: 4872
    Points: 1,844
    Helping HandTeam Member
    Rank: Community Hero

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

The topic ‘cmdlets vs functions’ is closed to new replies.