Search code examples
powershellargs

Visual Code launch.json args cannot handle space in datetime


While debugging powershell in Visual Code I am setting my launch.json file.

{
"version": "0.2.0",
"configurations": [
    {
        "name": "PowerShell",
        "type": "PowerShell",
        "request": "launch",
        "program": "${file}",
        "args": ["param1", "param2", "param3", "10/05/2016 13:25:00"],
        "cwd": "${file}"
    }
]
}

I get this error: A positional parameter cannot be found that accepts argument '13:25:00'.

The powershell looks like this:

Param(
[Parameter(Mandatory=$True,Position=1)]
[string[]]$Param1,
[Parameter(Mandatory=$True,Position=2)]
[string[]]$Param2,
[Parameter(Mandatory=$True,Position=3)]
[string[]]$Param3,
[Parameter(Mandatory=$True,Position=4)]
[datetime]$MyDateTime)

Any ideas on how I can escape this?


Solution

  • Try "args": "param1 param2 param3 '10/05/2016 13:25:00'". IIRC we went back and forth on taking the args as an array or a single string. Seemed like a single string worked better.