Erhalte den nächsten Index als dreistellige Zahl

Get the next index as a three-digit number

Parameters are defined at the first non-comment line within a script of function.

param (
    $Noun,
    $Verb
)

Specify data types of parameters

Identify flag

  • Boolean is true or false.
param(
    [Switch] $Force
)

Identify specific type

param (
    [DateTime] $Date
)

Validate out of predefined options

  • Enables AutoComplete.
param (
    [ValidateSet("World", "Galaxy", "Universe")] $Noun
)

Provide default values

Set default value

param (
    $Noun = "none"
)

Set default via command

param (
    $Date = $(Get-Date)
)

Identify optional public properties of parameters

Require parameter

param (
    [Parameter(Mandatory,HelpMessage="Enter your name")] $Name
)
AttributeDefaultDescription
MandatoryfalseMake parameter mandatory and prompt for value when the user does not supply one
ParameterSetNameDefine mutually exclusive parameters
PositionAssign positions to parameters and use arguments without parameter names
ValueFromPipelinefalseAssign pipeline input to a parameter
ValueFromPipelineByPropertyNameAssign a specific property of pipeline input to a parameter
ValueFromRemainingArgumentsfalseCreate a ParamArray and assign any unbound argument to a parameter
DontShowfalseHide parameter in IntelliSense and tab completion
HelpMessageProvide a help message for mandatory parameters
HelpMessageBaseNameName of resource assembly that contains compiled help messages
HelpMessageResourceIdResource identifier for help message

Sources:

Related:
Naming Convention - Name PowerShell functions with one of the predefined verbs

Tags:
Programm PowerShell - Learn PowerShell’s programming paradigms