Why are scripted cmdlets listed as functions? Why are scripted cmdlets listed as functions? powershell powershell

Why are scripted cmdlets listed as functions?


There potentially isn't much difference between a function and a cmdlet, but that depends on how much work you're willing to put into writing the function. Don Jones wrote an article on TechNet back when these first came out to highlight some of these differences.

These functions, written entirely in script, have the same capabilities as a “real” cmdlet written in C# or Visual Basic and compiled in Visual Studio. These advanced functions (they were originally called “script cmdlets” early in the v2 development cycle) help you write more flexible functions you can then use seamlessly alongside regular cmdlets.

...

The real difference between a mere function and a full cmdlet is that cmdlets support powerful parameter bindings. You can use positional parameters, named parameters, mandatory parameters, and even do basic parameter validation checks—all by simply describing the parameter to the shell.

The code example you've offered already begins to blur the lines between the two by allowing a host of addition parameters via [CmdletBinding()], and beginning to describe a brand new parameter called $Name. For example, you could now use Write-Verbose anywhere in that function, and call the -Verbose flag to see those statements without having to do any additional work.

Functionally, the end results of a compiled cmdlet or a function written in powershell don't have to be very different at all -- it seems to be more a matter of distinguishing compiled cmdlets from scripted functions.