CmdletBinding properties

The full set of possible values that may be assigned can be viewed by creating an instance of the CmdletBinding object:

PS> [CmdletBinding]::new()

PositionalBinding : True
DefaultParameterSetName :
SupportsShouldProcess : False
SupportsPaging : False
SupportsTransactions : False
ConfirmImpact : Medium
HelpUri :
RemotingCapability : PowerShell
TypeId : System.Management.Automation.CmdletBindingAttribute

For example, the output from the preceding command shows the existence of a PositionalBinding property. Setting this to false disables automatic position binding:

function Test-Binding {
[CmdletBinding(PositionalBinding = $false)]
param (
$Parameter1
)
}

When the preceding function is called, and a value for Parameter1 is given by position, an error will be thrown:

PS> Test-Binding 'value'
Test-Binding : A positional parameter cannot be found that accepts argument 'value'.
At line:1 char:1
+ test-binding 'value'
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Test-Binding], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Test-Binding

The most commonly used properties of CmdletBinding are SupportsShouldProcess and DefaultParameterSetName. DefaultParameterSetName will be explored in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.114.38