Dots in function parameter name Dots in function parameter name powershell powershell

Dots in function parameter name


Windows PowerShell Language Specification Version 3.0.The section 2.3.4 Parameters says

parameter-char:Any Unicode character except    {   }   (   )   ;   ,   |   &   .   [    colon    whitespace    new-line-character

Thus, the dot is not really a valid parameter name character.

Interestingly, it is possible to define a parameter with dots like ${...}

param (    [string] ${Dmaven.failsafe.debug})

PowerShell allows the above. But it is difficult to specify such a parameter name on invoking a command.


Some experiments:

function Test-ParameterWithDots {    param(        [string]${Parameter.With.Dots}    )    "Parameter : ${Parameter.With.Dots}"}# OKTest-ParameterWithDots value1# not OKTest-ParameterWithDots -Parameter.With.Dots value2# workaround with splatting$params = @{ 'Parameter.With.Dots' = 'value3' }Test-ParameterWithDots @params

Output:

Parameter : value1Parameter : .With.DotsParameter : value3

So with spatting we still can specify such a parameter name.


The notation you should be able to use to allow this is with curly braces

${Dmaven.failsafe.debug}

This is used when the name contains special characters. Typing in camelCase is usually to preferred method of defining variables.