When you create a PowerShell function, all parameters are positional until you start adding the “Position” attribute. Once you start to do this, all parameters...
When you create a PowerShell function, all parameters are positional until you start adding the “Position” attribute. Once you start to do this, all parameters with no “Position” are suddenly named and must be specified. Have a look:
Example of a Classic Function Declaration
Here is a classic function declaration, producing three positional parameters:
functionTest-Command
{
param
(
[string]$Name,
[int]$ID,
[string]$Email
)
# TODO: Code using the parameter values
}
What is the difference? You do not need to specify the parameter names -Name and -ID, but you must specify -Email if you want to submit a value to this third parameter. In the first example, all three parameters could be used positionally.