Cmdlets were the original way of extending PowerShell. Cmdlets have basically the same functionality as functions (PowerShell cmdlets are comparable with advanced functions), but they are implemented in C# and packaged in .NET assemblies.
It is more common to implement scripts as functions in PowerShell files as they can be edited easily. Still, cmdlets might be useful in a few scenarios:
- There is a significant investment in C# as a scripting language
- The code needs to be protected (.NET assemblies can be obfuscated)
In the following example, we define the GetListCommand cmdlet. It inherits from the Cmdlet class from the System.Management.Automation namespace.
To consume SharePoint, the Cmdlet class accepts a ClientContext parameter ...