PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.67k stars 478 forks source link

Getting ParseException when opening PowerShell extension terminal in VS code. #5010

Open ComputerScienceSean opened 5 days ago

ComputerScienceSean commented 5 days ago

Prerequisites

Summary

I am experiencing a problem when my Visual Studio Code PowerShell Extension Terminal starts.

I am receiving the following error:

ParseException: At line:3 char:141
+ … l' -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ScriptBlock.Create(ExecutionContext context, String script)
   at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.RunScript[T](CommandInvocationIntrinsics cii, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsExtensions.RunScript[T](PSCmdlet cmdlet, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.GetScriptCmdlets(PSCmdlet cmdlet, String scriptFolder)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()

The error prints itself multiple times when the PowerShell Extension terminal window opens up. It still allows me to run cmdlets, but I would like to understand the cause of this issue.

I am uncertain whether this issue presents itself since I have an apostrophe (') in my name, so I tried moving my OneDrive folder to another path without the apostrophe. This did not solve my issue.

In the regular PowerShell terminal (pwsh) I am not receiving this error.

PowerShell Version

PS C:\Users\<user>\OneDrive - <companyname>\<companyname>\VSCodeFiles\LocalVSCProjects> $PSVersionTable; $Host

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.2.2
InstanceId       : fb00f15d-def3-4e93-b4ac-ed32b9306f59
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : da-DK
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

PS C:\Users\<user>\OneDrive - <companyname>\<companyname>\VSCodeFiles\LocalVSCProjects> code --version

1.90.2
5437499feb04f7a586f677b155b039bc2b3669eb
x64

Extension Version

PS C:\Users\<user>\OneDrive - <companyname>\<companyname>\VSCodeFiles\LocalVSCProjects> code --list-extensions --show-versions | Select-String powershell

ms-vscode.powershell@2024.2.2

Steps to Reproduce

No code execution is required. The error occurs on startup of the terminal window of the PowerShell extension. Below is the full error.

PS C:\Users\sean\OneDrive - <redacted>\<redacted>\VSCodeFiles\LocalVSCProjects> ParseException: At line:3 char:141
+ … l' -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ScriptBlock.Create(ExecutionContext context, String script)
   at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.RunScript[T](CommandInvocationIntrinsics cii, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsExtensions.RunScript[T](PSCmdlet cmdlet, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.GetScriptCmdlets(PSCmdlet cmdlet, String scriptFolder)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()
ParseException: At line:3 char:141
+ … l' -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ScriptBlock.Create(ExecutionContext context, String script)
   at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.RunScript[T](CommandInvocationIntrinsics cii, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsExtensions.RunScript[T](PSCmdlet cmdlet, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.GetScriptCmdlets(PSCmdlet cmdlet, String scriptFolder)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()
ParseException: At line:3 char:139
+ … m' -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ScriptBlock.Create(ExecutionContext context, String script)
   at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.RunScript[T](CommandInvocationIntrinsics cii, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsExtensions.RunScript[T](PSCmdlet cmdlet, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.GetScriptCmdlets(PSCmdlet cmdlet, String scriptFolder)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()
ParseException: At line:3 char:142
+ … s' -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ScriptBlock.Create(ExecutionContext context, String script)
   at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.RunScript[T](CommandInvocationIntrinsics cii, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsExtensions.RunScript[T](PSCmdlet cmdlet, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.GetScriptCmdlets(PSCmdlet cmdlet, String scriptFolder)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()
ParseException: At line:3 char:142
+ … s' -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: '.
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ScriptBlock.Create(ExecutionContext context, String script)
   at System.Management.Automation.CommandInvocationIntrinsics.InvokeScript(String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.RunScript[T](CommandInvocationIntrinsics cii, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsExtensions.RunScript[T](PSCmdlet cmdlet, String script)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.PsHelpers.GetScriptCmdlets(PSCmdlet cmdlet, String scriptFolder)
   at Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()

Visuals

No response

Logs

No response

andyleejordan commented 5 days ago

Hi,

Please open an issue with Azure PowerShell as the stack trace you shared shows its emanating from their code:

Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.PowerShell

I'm going to guess you're probably right about the apostrophe in your name, so share that with them as well. As to why it's happening on start-up of the extension, I can only surmise you're loading the Azure PowerShell module in your profile, or having it installed has injected some startup sequence.

But the PowerShell extension for VS Code does not ship nor load the Azure PowerShell module.

Cheers!

github-actions[bot] commented 5 days ago

This issue has been labeled as resolved, please verify the provided fix (or other reason).