Vscode-powershell: Unable to debug scripts in folder with ampersand in title

Created on 3 Jul 2018  路  11Comments  路  Source: PowerShell/vscode-powershell

Issue Description

I am experiencing a problem with running debug on script residing in a folder path containing an ampersand.

When running these i get the following error:
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

This works fine in ISE.

Unfortunately as this is a hardcoded onedrive path i can't easily modify this.

Attached Logs

Environment Information

Visual Studio Code

| Name | Version |
| --- | --- |
| Operating System | Windows_NT x64 10.0.17134 |
| VSCode | 1.24.1|
| PowerShell Extension Version | 1.7.0 |

PowerShell Information

|Name|Value|
|---|---|
|PSVersion|5.1.17134.112|
|PSEdition|Desktop|
|PSCompatibleVersions|1.0 2.0 3.0 4.0 5.0 5.1.17134.112|
|BuildVersion|10.0.17134.112|
|CLRVersion|4.0.30319.42000|
|WSManStackVersion|3.0|
|PSRemotingProtocolVersion|2.3|
|SerializationVersion|1.1.0.1|

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)

|Extension|Author|Version|
|---|---|---|
|cisco|jamiewoodio|1.0.1|
|Material-theme|zhuangtongfa|2.15.0|
|one-monokai|azemoh|0.3.4|
|PowerShell|ms-vscode|1.7.0|
|slack-theme|felipe-mendes|1.6.1|
|team|ms-vsts|1.136.0|
|vscode-icons|robertohuertasm|7.24.0|;

Area-Debugging Issue-Bug

Most helpful comment

Just confirming this seems to be fixed in the latest version of the Powershell extension great work馃憤

All 11 comments

It sounds like you're not quoting the path properly? That error is from powershell trying to parse an ampersand where it doesn't belong. Currently it's only supported in two locations: Redirection and as the call operator.

@Lowestkillcount Can you give an example of the path that isn't working? Also, have you tried this in PowerShell without VSCode? If it reproduces in PowerShell without VSCode, it would probably be a PowerShell issue (or could be by design).

Interestingly enough - i've just reopened the same file i was working on and this doesn't happen anymore.... however this is on a different PC so maybe something in the other environment..

The issue was when working on a file in path:
C:\Users\LKC\Onedrive - S&M Company Pty Ltd Script.ps1

Using the DebugStart Debugging option in the menu would result in the console throwing an error like below.

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

As when you do this the debugger runs the whole script path against the console like this
PowerShell Integrated Console

PS C:\Users\LKC\Onedrive - S&M Company Pty Ltd> c:\Users\LKC\Onedrive - S&M Company Pty Ltd Script.ps1

I'll double check on my work laptop on Monday if it still occurs there, it may be some obscure setting in my profile causing issues.

I'm having trouble reproducing this currently. @DanrwAU, are you still seeing this issue?

@DanrwAU are you still having this problem in 1.9.0? I fixed a URI issue that would explain this bug and curious to see if it persists.

Sorry missed the last update :smile:

I haven't had it happen recently, i may have debugged a few times but generally i avoid using VSCode to debug as all my scripts live in a path with an ampersand.

I'll test it out and let you know

No worries 鈥斅爐otally understand

PowerShell Integrated Console

. c:\Users\username\OneDrive` -` Company &Company` Corporation\Repositories\Office` 365\Migrate-Onedrive.ps1 -Verb RunAs

At line:1 char:42
+ . c:\Users\username\OneDrive` -` Company&Company` Corporation\Repositories ...
+                                          ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

Still happening.

Bugger. I think we've just identified where the problem is at least, so a fix is within reach.

I have a fix for this in the PR shown above, so hopefully we can build a new extension pre-release artefact within the week for you to test @DanrwAU

Just confirming this seems to be fixed in the latest version of the Powershell extension great work馃憤

Was this page helpful?
0 / 5 - 0 ratings