Specifying function attributes
In case of advanced functions, we use Cmdlet bindings to control the feature or function of the function itself. With this, we define how the function works or behaves.
Addition of the [CmdletBinding()]
line allows you to define these controls in an advanced function. Note that with the use of CmdletBinding()
, we get the $PSCmdlet
automatic variable, but the $Args
variable is not available in these functions.
In advanced functions, with the CmdletBinding
attribute, unknown parameters and positional arguments that do not have any matching positional parameters results in parameter binding to fail.
Let's examine the available options with the CmdletBinding()
attribute and their meaning:
<# Comment Based Help #> function <function_name> { [CmdletBinding(ConfirmImpact=<String>, DefaultParameterSetName=<String>, HelpURI=<URI>, SupportsPaging=<Boolean>, ...