I have a tool that accepts parameters like this (e.g. in test.ps1
):
foo.exe -name="john"
So, each parameter is specified with a single hyphen -
, the name, an equals =
, and then the value of the parameter.
When I invoke this exact expression from PowerShell, it executes without any problems. However, when one of the values contains a period .
like this:
foo.exe -name="john.doe"
Running it causes a syntax error:
$ ./test.ps1 The string starting: At test.ps1:1 char:24 + foo.exe -name="john.doe <<<< " is missing the terminator: ". At test.ps1:1 char:25
+ foo.exe -name="john.doe" <<<<
+ CategoryInfo : ParserError: (:String) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Some ways that I can prevent PowerShell from interpreting this are:
foo.exe "-name=`"john.doe`""
foo.exe '-name="john.doe"'
- PowerShell V3+:
foo.exe --% -name="john.doe"
$nameArg = "john.doe"; foo.exe -name="$nameArg"
However, some of these options prevent interpolation of variables. Are there other ways to stop PowerShell from causing syntax issues? In this specific instance (adding the period), why is PowerShell having issues interpreting this?