PowerShell / vscode-powershell

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

Cannot run PowerShellEditorServices when execution policy is set to AllSigned #1048

Closed ChadThomsen closed 5 years ago

ChadThomsen commented 7 years ago

System Details

PS C:\Users\q794776> $PSVersionTable

Name Value


PSVersion 5.0.10586.117 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.10586.117 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:
PowerShell Integrated Console does not work.....

code -v
$pseditor.EditorServicesVersion
code --list-extensions --show-versions
$PSVersionTable

Issue Description

Terminal does not work. It worked before I performed the VScode upgrade which was done today.

Attached Logs

10/9/2017 3:28:03 PM [NORMAL] - Visual Studio Code v1.17.0 64-bit 10/9/2017 3:28:03 PM [NORMAL] - PowerShell Extension v1.4.3 10/9/2017 3:28:03 PM [NORMAL] - Operating System: Windows 64-bit 10/9/2017 3:28:03 PM [NORMAL] - Language server starting -- 10/9/2017 3:28:03 PM [NORMAL] - exe: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe 10/9/2017 3:28:03 PM [NORMAL] - args: C:\Users\q794776.vscode\extensions\ms-vscode.powershell-1.4.3\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.4.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.4.3' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\q794776.vscode\extensions\ms-vscode.powershell-1.4.3\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\q794776.vscode\extensions\ms-vscode.powershell-1.4.3\logs\1507577283-8fc44e83-a80e-4a7f-bcf2-67761b34ccaf1507577267715\EditorServices.log' -SessionDetailsPath 'C:\Users\q794776.vscode\extensions\ms-vscode.powershell-1.4.3\sessions\PSES-VSCode-4180-886972' -FeatureFlags @() 10/9/2017 3:28:03 PM [NORMAL] - powershell.exe started, pid: 9620 10/9/2017 3:29:03 PM [NORMAL] - Language server startup failed. 10/9/2017 3:29:03 PM [ERROR] - The language service could not be started: 10/9/2017 3:29:03 PM [ERROR] - Timed out waiting for session file to appear.

ChadThomsen commented 7 years ago

I reinstalled Visual Studio Code, and re-installed the PowerShell plugin and now the terminal loads but it takes a long time to load. I did not time it but it seemed to take about 90+ seconds.

daviwil commented 6 years ago

Hey Chad, has the situation improved for you with VS Code 1.17.2? I believe there was a performance issue with the Integrated Terminal that might have been causing this.

legendaryleo7 commented 6 years ago

Hello, I am having the same issue.

11/13/2017 9:33:29 AM [NORMAL] - Visual Studio Code v1.19.0-insider 64-bit
11/13/2017 9:33:29 AM [NORMAL] - PowerShell Extension v1.5.0
11/13/2017 9:33:29 AM [NORMAL] - Operating System: Windows 64-bit
11/13/2017 9:33:29 AM [NORMAL] - Language server starting --
11/13/2017 9:33:29 AM [NORMAL] -     exe: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
11/13/2017 9:33:29 AM [NORMAL] -     args: C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.5.0' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\logs\1510583609-3cd56bc6-8615-4cee-8a94-bb3b2a2e661d1510583606672\EditorServices.log' -SessionDetailsPath 'C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\sessions\PSES-VSCode-4628-572597' -FeatureFlags @()
11/13/2017 9:34:29 AM [NORMAL] - Language server startup failed.
11/13/2017 9:34:29 AM [ERROR] - The language service could not be started: 
11/13/2017 9:34:29 AM [ERROR] - Timed out waiting for session file to appear.

I tried running Start-EditorServices myself to see a more verbose version of what was happening: I ran C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.5.0' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\logs\1510583609-3cd56bc6-8615-4cee-8a94-bb3b2a2e661d1510583606672\EditorServices.log' -SessionDetailsPath 'C:\src\ProgramFiles\VSCode\.vscode\extensions\ms-vscode.powershell-1.5.0\sessions\PSES-VSCode-4628-572597' -FeatureFlags @()

I got: Missing an argument for parameter 'FeatureFlags'. Specify a parameter of type 'System.String[]' and try again.

Interestingly enough, it works fine when running VSCode as an Administrator.

I can confirm the bug exists on both Stable 1.18.0 and Insiders 1.19.0

jcoryatjr commented 6 years ago

I am seeing the same thing.

12/8/2017 8:40:31 AM [NORMAL] - Visual Studio Code v1.18.1 64-bit 12/8/2017 8:40:31 AM [NORMAL] - PowerShell Extension v1.5.1 12/8/2017 8:40:31 AM [NORMAL] - Operating System: Windows 64-bit 12/8/2017 8:40:31 AM [NORMAL] - Language server starting -- 12/8/2017 8:40:31 AM [NORMAL] - exe: C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe 12/8/2017 8:40:31 AM [NORMAL] - args: C:\Users\jcoryat.vscode\extensions\ms-vscode.powershell-1.5.1\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.5.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.1' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\jcoryat.vscode\extensions\ms-vscode.powershell-1.5.1\modules' -EnableConsoleRepl -WaitForDebugger -LogLevel 'Normal' -LogPath 'C:\Users\jcoryat.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1512747631-528dcf93-d895-4dfe-afe3-f244164a48f81512747623009\EditorServices.log' -SessionDetailsPath 'C:\Users\jcoryat.vscode\extensions\ms-vscode.powershell-1.5.1\sessions\PSES-VSCode-16108-589881' -FeatureFlags @() 12/8/2017 8:40:31 AM [NORMAL] - powershell.exe started, pid: 10856 12/8/2017 8:41:31 AM [NORMAL] - Language server startup failed. 12/8/2017 8:41:31 AM [ERROR] - The language service could not be started: 12/8/2017 8:41:31 AM [ERROR] - Timed out waiting for session file to appear.

In the log it also shows that it downloads omnisharp every time I try to run a powershell script. At the end it will show a message at the top of the editor "Cannot read property 'length' of undefined"

I overrode the following settings:

"powershell.powerShellExePath": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Powershell.exe",
"powershell.developer.editorServicesWaitForDebugger": true,
"omnisharp.path": "c:\\omnisharp-win-x64-1.26.\\OmniSharp.exe",
"omnisharp.waitForDebugger": true,
rkeithhill commented 6 years ago

@jcoryatjr You do not want the following setting set to true unless you are debugging the PowerShell Editor Services DLL itself:

"powershell.developer.editorServicesWaitForDebugger": true,

This setting, when set to true, triggers a debug break in the DLL startup code in which the start up waits until you attach a C# debugger - which is perhaps why it is attempting to download/start OmniSharp.

tmknight commented 6 years ago

Regression in 2018-01-30 Insiders: Version 1.20.0-insider Commit eed7e193125f3d4cfebe2089d1b2a9c674388754 Date 2018-01-30T09:51:29.494Z Shell 1.7.9 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64

1/30/2018 8:04:58 AM [NORMAL] - Visual Studio Code v1.20.0-insider 64-bit 1/30/2018 8:04:58 AM [NORMAL] - PowerShell Extension v1.5.1 1/30/2018 8:04:58 AM [NORMAL] - Operating System: Windows 64-bit 1/30/2018 8:04:58 AM [NORMAL] - powershell.exe terminated or terminal UI was closed 1/30/2018 8:05:58 AM [NORMAL] - Language server startup failed. 1/30/2018 8:05:58 AM [ERROR] - The language service could not be started: 1/30/2018 8:05:58 AM [ERROR] - Timed out waiting for session file to appear.

TylerLeonhardt commented 6 years ago

@tmknight (or anyone with this issue) can you enable verbose logging and attach the logs here?

Here are instructions: https://github.com/PowerShell/vscode-powershell/#2-capture-verbose-logs-and-send-them-to-us

tmknight commented 6 years ago

Logs attached:

1517332481-92605cef-ce86-4904-8772-bfd9f32651c61517332479200.zip

TylerLeonhardt commented 6 years ago

@tmknight looks like the integrated terminal in VSCode (insiders) isn't working at all in today's daily build.

With the PowerShell extension disabled, if you open the integrated terminal like so: image

The terminal flashes open and disappears.

This would explain why we are seeing the error you are getting.

My recommendation:

The issue opened on them for this is here: https://github.com/Microsoft/vscode/issues/42516 .... and they already have a fix committed 🎉

TylerLeonhardt commented 6 years ago

To @jcoryatjr, @legendaryleo7, and @phunkodelic. Are you folks still experiencing this issue on stable (or any insider build before today)?

tmknight commented 6 years ago

@tylerl0706 RE: PS Terminal. Yes, I observed that with Integrated and Native RE: Stable - Agreed. I keep both installed.

Let me know if you need additional info - though I see Insiders has been updated and the issue is resolved.

Cheers

legendaryleo7 commented 6 years ago

@tylerl0706 I had this problem as far back as 2017-11-13. My integrated terminal stays open but stays stuck at a blank screen. I never get a prompt.

Here's the logs from Stable - 2018-01-25: 1517364087-05661b6c-5d4b-4b3b-be4e-5c550c0e6d391517364064920.zip

And Insiders - 2018-01-30 1517365011-bc4b9cc9-dd9f-4ce6-9a02-39f2c88141c31517364997824.zip

I've noticed that there seems to be no issue when running with elevated permissions. I use a standard account and elevate when updating/installing stuff with an admin account. I wonder if that's related to it (in my case at least). I'm using other terminal emulators like ConEmu and Cmder with no problem.

kilkikou commented 6 years ago

I have also the same issue. Here is the log.

2018-2-13 11:06:32 [NORMAL] - Visual Studio Code v1.20.0 64-bit
2018-2-13 11:06:32 [NORMAL] - PowerShell Extension v1.5.1
2018-2-13 11:06:32 [NORMAL] - Operating System: Windows 10 64-bit
2018-2-13 11:06:32 [NORMAL] - Language server starting --
2018-2-13 11:06:32 [NORMAL] -     exe: C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe
2018-2-13 11:06:32 [NORMAL] -     args: C:\Users\login\.vscode\extensions\ms-vscode.powershell-1.5.1\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.5.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.1' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\login\.vscode\extensions\ms-vscode.powershell-1.5.1\modules' -EnableConsoleRepl -LogLevel 'Verbose' -LogPath 'C:\Users\login\.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518516392-f346670a-6685-430d-9237-d544e91ce2811518516374265\EditorServices.log' -SessionDetailsPath 'C:\Users\login\.vscode\extensions\ms-vscode.powershell-1.5.1\sessions\PSES-VSCode-1344-985088' -FeatureFlags @()
2018-2-13 11:07:38 [NORMAL] - Language server startup failed.
2018-2-13 11:07:38 [ERROR] - The language service could not be started: 
2018-2-13 11:07:38 [ERROR] - Timed out waiting for session file to appear.

I've enable the loging to verbose, but nothing more is added to the logfile. And the file EditorServices.log is not created...I'm running vscode without administrator rights.

Any ideas? Thank you.

bjmaynard01 commented 6 years ago

I can confirm, I am having the same problem with VSCode 1.19.2 and PowerShell extension 1.5.1. No integrated terminal will open, powershell or otherwise unless I run the program with elevated credentials. Logs are the same as what everyone else is seeing, but have been pasted in below.

2/13/2018 8:13:36 PM [NORMAL] - Visual Studio Code v1.19.2 64-bit 2/13/2018 8:13:36 PM [NORMAL] - PowerShell Extension v1.5.1 2/13/2018 8:13:36 PM [NORMAL] - Operating System: Windows 64-bit 2/13/2018 8:13:36 PM [NORMAL] - Path specified by 'powerShellExePath' setting - '' - not found, reverting to default PowerShell path. 2/13/2018 8:13:36 PM [NORMAL] - Language server starting -- 2/13/2018 8:13:36 PM [NORMAL] - exe: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 2/13/2018 8:13:36 PM [NORMAL] - args: C:\Users\.vscode\extensions\ms-vscode.powershell-1.5.1\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.5.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.1' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\bryan.maynard.vscode\extensions\ms-vscode.powershell-1.5.1\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518570816-9847f26b-3ab2-4368-a1f3-a9c76d0125911518570813582\EditorServices.log' -SessionDetailsPath 'C:\Users\.vscode\extensions\ms-vscode.powershell-1.5.1\sessions\PSES-VSCode-2268-296277' -FeatureFlags @() 2/13/2018 8:14:36 PM [NORMAL] - Language server startup failed. 2/13/2018 8:14:36 PM [ERROR] - The language service could not be started: 2/13/2018 8:14:36 PM [ERROR] - Timed out waiting for session file to appear.

rkeithhill commented 6 years ago

Is there an EditorServices.log file at this location: 'C:\Users\<user>\.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518570816-9847f26b-3ab2-4368-a1f3-a9c76d0125911518570813582\EditorServices.log'. If so, could you post the contents here if short. If long, please zip and attach. Thanks.

bjmaynard01 commented 6 years ago

There isn't an EditorServices.log file in the folder, only a vscode-powershell.log file (note directory changed due to new run, but same log output)

image

rkeithhill commented 6 years ago

OK, well that is consistent with the PSES module not getting far enough along to even create the log file.

rkeithhill commented 6 years ago

It looks like you redacted your username for the log output but this piece remains: C:\Users\bryan.maynard.vscode\.... Is that exactly what was in the log file? I suspect that should be C:\Users\bryan.maynard\.vscode\... with the \ between user name and the .vscode dir. Assuming that was just a mistake in the redaction, can you try executing this from a PowerShell prompt:

C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\scripts\Start-EditorServices.ps1 -EditorServicesVersion '1.5.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.1' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518570816-9847f26b-3ab2-4368-a1f3-a9c76d0125911518570813582\EditorServices.log' -SessionDetailsPath 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\sessions\PSES-VSCode-2268-296277' -FeatureFlags @()

Is there any error message output?

bjmaynard01 commented 6 years ago

You are correct, it was a missed/error redaction...anywho, when I run the command you gave me in a PS window, it goes to PowerShell Integrated Console, and then nothing else happens.

rkeithhill commented 6 years ago

So in this case, there is an EditorServices.log file in the C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518570816-9847f26b-3ab2-4368-a1f3-a9c76d0125911518570813582 dir? Trying to ascertain that PSES started up correctly. If so, then that points to something going wrong when trying to attach this console to a terminal window in VSCode.

bjmaynard01 commented 6 years ago

Yes, pasted below

2/13/2018 8:31:46 PM [NORMAL] - Method "StartLogging" at line 144 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs

PowerShell Editor Services Host v1.5.1.0 starting (pid 3312)...

  Host application details:

    Name:      Visual Studio Code Host
    ProfileId: Microsoft.VSCode
    Version:   1.5.1
    Arch:      64-bit

  Operating system details:

    Version: Microsoft Windows NT 10.0.16299.0
    Arch:    64-bit

2/13/2018 8:31:46 PM [NORMAL] - Method "StartLanguageService" at line 180 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs

Language service started, listening on port 21129

2/13/2018 8:31:47 PM [NORMAL] - Method "StartDebugService" at line 254 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs

Debug service started, listening on port 13186
rkeithhill commented 6 years ago

OK, so the PSES module starts up correctly but something seems to go wrong in trying to attach it to the VSCode terminal window. Do you have any special integrated terminal settings set in your user (or workspace) settings?

bjmaynard01 commented 6 years ago

I don't, it's a fresh installation

rkeithhill commented 6 years ago

Hmm...

rkeithhill commented 6 years ago

Is there any difference if you execute this (was missing some PowerShell.exe params):

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "& 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\scripts\Start-EditorServices.ps1' -EditorServicesVersion '1.5.1' -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '1.5.1' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518570816-9847f26b-3ab2-4368-a1f3-a9c76d0125911518570813582\EditorServices.log' -SessionDetailsPath 'C:\Users\bryan.maynard\.vscode\extensions\ms-vscode.powershell-1.5.1\sessions\PSES-VSCode-2268-296277' -FeatureFlags @()"
bjmaynard01 commented 6 years ago

Unfortunately, no, the console goes to the same integrated console message with the same output in the EditorServices log...this really makes no sense. Makes me believe it's some type of security control that is in place on my work laptop.

rkeithhill commented 6 years ago

AFAICT that is exactly the exe & args passed to the VSCode API that creates the terminal (starts PSES) e.g.

this.consoleTerminal =
    vscode.window.createTerminal(
        this.title,
        powerShellExePath,
        powerShellArgs);

Can you try an experiment? Start task manager, go to the Details pane and sort by Name and then find the PowerShell processes and select one (to keep window from scrolling). Now start a debug session in VSCode and see if a new PowerShell appears in the list. It might not run for long. You might want to set the task manager View -> Update speed to High to increase the chances of seeing PowerShell.exe spin up. If this doesn't work, there is a WMI event that will fire whenever a new process starts but I don't remember the syntax for that command off the top of my head.

bjmaynard01 commented 6 years ago

So, I did do this, and I briefly saw another powershell process spawn, then die. This happened about 4 times before VSCode timed out trying to load the engine.

rkeithhill commented 6 years ago

Thanks for checking that. Can you check your event log (both Applications and WindowsPowerShell) to see if there are any clues as to why the PowerShell process exited early:

image

bjmaynard01 commented 6 years ago

I'm not seeing anything in either log pertaining to the problem. I appreciate all the help, but at this point I think I'm simply better off using the PS ISE

rkeithhill commented 6 years ago

Totally understand. Thanks for all your help.

rkeithhill commented 6 years ago

@bjmaynard01 (or anyone game for this experiment) Could you try one more thing for me? I have fixed a bug related to testing for socket ports in use. Can you grab this file - https://raw.githubusercontent.com/PowerShell/vscode-powershell/b25e1abe5d0c9539f0f06e025089bf2c0a504ab0/scripts/Start-EditorServices.ps1 and use its contents to completely replace the contents of $Home\.vscode\extensions\ms-vscode.powershell-1.5.1\scripts\Start-EditorServices.ps1. Now try again. If the console still fails to start at least there should be a Start-EditorServices.log file in the logs dir for the session. Could you paste the contents here? Thanks!!

Ryoken0367 commented 6 years ago

I'm having the same issue, only in the 1.20.1 release; everything was fine in 1.20. I tried your replacement script, and I'm not seeing the log file; however, instead of just closing the terminal, VS Code is now displaying the below:

An error occurred while starting PowerShell Editor Services:

AuthorizationManager check failed. at System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host) at Microsoft.PowerShell.Commands.ModuleCmdletBase.GetScriptInfoForFile(String fileName, String& scriptName, Boolean checkExecutionPolicy) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleNamedInManifest(PSModuleInfo parentModule, ModuleSpecification moduleSpecification, String moduleBase, Boolean searchModulePath, String prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, Boolean loadTypesFiles, Boolean loadFormatFiles, Object privateData, Boolean& found, String shortModuleName, Nullable1 manifestLanguageMode) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingExtensions(PSModuleInfo parentModule, String moduleName, String fileBaseName, String extension, String moduleBase, String prefix, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound) at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(PSModuleInfo parentModule, Boolean found, IEnumerable1 modulePath, String name, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, PSModuleInfo& module) at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name) at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available. at Microsoft.PowerShell.ConsoleHostUserInterface.HandleThrowOnReadAndPrompt() at Microsoft.PowerShell.ConsoleHostUserInterface.PromptForChoice(String caption, String message, Collection1 choices, Int32 defaultChoice) at System.Management.Automation.Internal.Host.InternalHostUserInterface.PromptForChoice(String caption, String message, Collection`1 choices, Int32 defaultChoice) at Microsoft.PowerShell.PSAuthorizationManager.AuthenticodePrompt(String path, Signature signature, PSHost host) at Microsoft.PowerShell.PSAuthorizationManager.SetPolicyFromAuthenticodePrompt(String path, PSHost host, Exception& reason, Signature signature) at Microsoft.PowerShell.PSAuthorizationManager.CheckPolicy(ExternalScriptInfo script, PSHost host, Exception& reason) at Microsoft.PowerShell.PSAuthorizationManager.ShouldRun(CommandInfo commandInfo, CommandOrigin origin, PSHost host, Exception& reason) at System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)

Hope this helps track down this issue!

rkeithhill commented 6 years ago

Looks like the script can't run because I stripped out the authenticode signature. Crud. Looks like we will have to wait until 1.6.0 drops in order to get log file info from Start-EditorServices.ps1. Thanks for giving it a go!

Ryoken0367 commented 6 years ago

You're welcome. Any ETA on 1.6.0, or should I revert to VS Code 1.20?

Thank you!

rkeithhill commented 6 years ago

We're shooting for early next week. Crossing my fingers.

jcoryatjr commented 6 years ago

I did solve my problem. It was with a couple of links I had created in my modules folder. The links pointed to a location that no longer existed and defaulted to C:. Once I removed them, everything started working as it should. Now really loving the powershell in VSCode!

Ryoken0367 commented 6 years ago

Installed 1.6.0, same issue. I checked, and did not see a Start-EditorServices.log in the logs directory.

However, that being said, I had a thought. This issue seems to have cropped up for me after a policy change to force AllSigned for the powershell execution policy. I was able to revert the change back to RemoteSigned, and everything loads correctly now. As soon as I go back to AllSigned, the terminal fails to start. Wondering if others who are having this issue are also using AllSigned as their execution policy. Hopefully this helps track down and fix the issue!

rkeithhill commented 6 years ago

@Ryoken0367 Interesting. It sure would be nice to figure out which script is failing when the policy is set to AllSigned. When we invoke the script, we start a powershell process with the param -ExecutionPolicy Bypass. That "should" bypass the execution policy.

Can you open your User settings and the following setting:

    "powershell.developer.editorServicesLogLevel": "Diagnostic",

If you already have that setting, just make sure that it is set to Diagnostic. We only create the Start-EditorServices.log file when logging is set to Diagnostic. After setting it, restart VSCode and then see if there's a Start-EditorServices.log file. I'm curious if there are any clues in this log file when you have the policy set to AllSigned.

Ryoken0367 commented 6 years ago

I changed that setting, it was set to Normal; but I'm still not getting the log. Definitely happy to help track this down if you have anything else you need.

rkeithhill commented 6 years ago

Thanks! Do you see any text appear (however briefly) in the PowerShell Integrated Console terminal? The terminal window should show powershell.exe starting up and I'm guess it chokes on execution policy. If you have a screen capture tool, that might help capture text that appears very briefly. Although I've gotten pretty good at hitting PrintScreen key at the right time. :-)

One other thing to check is the WindowsPowerShell event log:

image Anything interesting in the entry that corresponds to the failed attempt to start the editor services?

Ryoken0367 commented 6 years ago

There was an error flashing up on the Terminal for a brief moment and disappearing; I was able to grab it with PrintScreen: error

As for the Event Log; there are 8 entries for that time. I can get screenshots of those too, if you'd like, but here's the first detail from each (oldest first): Provider "Registry" is Started. Provider "Alias" is Started. Provider "Environment" is Started. Provider "FileSystem" is Started. Provider "Function" is Started. Provider "Variable" is Started. Engine State is changed from None to Available. Engine State is changed from Available to Stopped.

Edit: Re-read your message, here's a screenshot of the "Available to Stopped" entry. eventlog

rkeithhill commented 6 years ago

Interesting, what do you get if you run this command from a PowerShell console:

Get-AuthenticodeSignature ~\.vscode\extensions\ms-vscode.powershell-1.6.0\scripts\Start-EditorServices.ps1

I get:

    Directory: C:\Users\hillr\.vscode\extensions\ms-vscode.powershell-1.6.0\scripts

SignerCertificate                         Status                                 Path
-----------------                         ------                                 ----
9ACA9419E53D3C9E56396DD2335FF683A8B0B8F3  Valid                                  Start-EditorServices.ps1

Also, what do you get for this command:

Get-Content -Stream Zone.Identifier ~\.vscode\extensions\ms-vscode.powershell-1.6.0\scripts\Start-EditorServices.ps1
rkeithhill commented 6 years ago

This is curious. Your error says it fails on line 1 char 3. This is line 1:

# PowerShell Editor Services Bootstrapper Script

Char 3 is the start of the text PowerShell but why wouldn't PowerShell see that whole line as a comment?

Ryoken0367 commented 6 years ago

From the first command I get the same result you do. Valid with the same thumbprint.

    Directory: C:\Users\WApgar\.vscode\extensions\ms-vscode.powershell-1.6.0\scripts

SignerCertificate                         Status                                 Path
-----------------                         ------                                 ----
9ACA9419E53D3C9E56396DD2335FF683A8B0B8F3  Valid                                  Start-EditorServices.ps1

From the second command I get an error:

Get-Content : Could not open the alternate data stream 'Zone.Identifier' of the file
'C:\Users\WApgar\.vscode\extensions\ms-vscode.powershell-1.6.0\scripts\Start-EditorServices.ps1'.
At line:1 char:1
+ Get-Content -Stream Zone.Identifier ~\.vscode\extensions\ms-vscode.po ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\WApgar...torServices.ps1:String) [Get-Content], FileNotFoundEx
   ception
    + FullyQualifiedErrorId : GetContentReaderFileNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand
rkeithhill commented 6 years ago

If the error mentioned Could not open the alternate data stream 'Zone.Identifier' of the file, that means the file has been "unblocked". OK so we have a valid Authenticode signature on the script and the script is not blocked.

What's your $PSVersionTable info? Also, can you copy/paste the text (or images) of these two event viewer events:

Engine State is changed from None to Available.
Engine State is changed from Available to Stopped.

Thanks again for all your help!

Ryoken0367 commented 6 years ago
PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

eventlog2 eventlog1

You're very welcome, whatever I can do to help get this figured out I will. I've loved using VS Code for writing my scripts and utilities; going back to the ISE is almost painful!

rkeithhill commented 6 years ago

Dang. I don't see anything out of the ordinary in those two events.

Hmm, I wonder if you are running into this (see his own, first comment) about group policy: https://community.spiceworks.com/topic/1451509-mdt-powershell-script-authorizationmanager-check-failed

Ryoken0367 commented 6 years ago

It seems this is definitely the issue; at least for me. We were pushing out the execution policy through GPO. As a test, I have turned that off, and left my machine set at AllSigned, and it runs just fine. Guess I'll be looking into pushing that out through a registry setting instead moving forward.

Thank you for all the help!

rdnaskelz commented 6 years ago

Can confirm, I have run into this problem right after we changed our script execution policy to AllSigned through GPO. So there is no way to bypass (pun intended?) execution policy that has been pushed out through group policy?

Edit: Wait, @rkeithhill, could you please advise me on why do you need to launch the script with Bypass execution policy even though it has valid signature?