Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ChadThomsen opened this issue Oct 9, 2017 · 82 comments
Assignees
Labels
Issue-Bug A bug to squash.

Comments

@ChadThomsen
Copy link

System Details

  • Operating system name and version: Windows 7 (x64)
  • VS Code version: 1.17.0
  • PowerShell extension version: 1.4.3
  • Output from $PSVersionTable:

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
Copy link
Author

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
Copy link
Contributor

daviwil commented Oct 25, 2017

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
Copy link

legendaryleo7 commented Nov 13, 2017

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
Copy link

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
Copy link
Contributor

@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
Copy link

tmknight commented Jan 30, 2018

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
Copy link
Member

@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
Copy link

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jan 30, 2018

@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:

  • always have vscode stable as well
  • wait until vscode fixes this issue in insiders

The issue opened on them for this is here: microsoft/vscode#42516
.... and they already have a fix committed 🎉

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jan 30, 2018

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

@tmknight
Copy link

@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
Copy link

@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
Copy link

kilkikou commented Feb 13, 2018

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
Copy link

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<user>.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<user>.vscode\extensions\ms-vscode.powershell-1.5.1\logs\1518570816-9847f26b-3ab2-4368-a1f3-a9c76d0125911518570813582\EditorServices.log' -SessionDetailsPath 'C:\Users<user>.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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

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

@rkeithhill
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

rkeithhill commented Feb 14, 2018

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
Copy link

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
Copy link
Contributor

rkeithhill commented Feb 14, 2018

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
Copy link

I don't, it's a fresh installation

@rkeithhill
Copy link
Contributor

Hmm...

@rkeithhill
Copy link
Contributor

rkeithhill commented Feb 14, 2018

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
Copy link

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

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
Copy link

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

@rjmholt
Copy link
Contributor

rjmholt commented Aug 23, 2018

Hi @davidm1984, we just did some work on this to make sure the certificates are all correct and up to date with the modules and scripts -- everything is Authenticode signed.

Would you be able to give some more info on the problem you experienced here and what you needed to do to work around it? You mentioned a build script, but do you mean the scripts to build from source? Or something in the released VSIX?

@rjmholt
Copy link
Contributor

rjmholt commented Oct 8, 2018

Hi all,
Are people still experiencing this issue?
I did some investigation into our signing about a month ago to get us signed with all the right certs -- want to see if that's solved anything or if we need to do more work here.

@Ryoken0367
Copy link

Hi @rjmholt,

I just tested this, and it seems to be working just fine now with the GPO set to AllSigned. No issues loading VS Code or the Powershell Extension at all. Intellisense and everything seems to be working as intended. (VS Code 1.28.0 and Powershell extension 1.9.0.)

Thank you for making that happen!

@rjmholt
Copy link
Contributor

rjmholt commented Oct 10, 2018

Closing for now -- if the issue recurs, we can reopen

@rjmholt rjmholt closed this as completed Oct 10, 2018
@Ryoken0367
Copy link

I know this was closed... but the issue seems to have popped up again with version 1.10.2 of the extension. With AllSigned GPO applied the language service fails to start. With Unrestricted it opens and runs just fine. Wondering if PS Editor Services was signed with the wrong cert again before publishing that version?

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Jan 8, 2019

@Ryoken0367 I want to make sure it's actually a result of the 1.10.2 release. Can you install 1.10.1 or 1.10?

Here's how to install an older version

@rjmholt rjmholt self-assigned this Jan 9, 2019
@rjmholt rjmholt changed the title The language service could not be started: Cannot run PowerShellEditorServices when execution policy is set to AllSigned Jan 9, 2019
@rjmholt
Copy link
Contributor

rjmholt commented Jan 9, 2019

I spoke with @TravisEz13 about this and confirmed that we are indeed signing correctly with the correct certificate.

The problem is that PowerShell trusts no signing certificate out of the box and you need to add the certificate to your trusted cert list yourself. This isn't something we should ever do automatically, but we should ideally ship a script that will do it all when invoked.

Here's an implementation:

# Temp file path to put the cert on
$certPath = Join-Path $env:TEMP powershelleditorservices.cer
# The signature for the EditorServices module file
$sig = Get-AuthenticodeSignature C:\Users\roholt\.vscode\extensions\ms-vscode.powershell*\modules\PowerShellEditorServices\PowerShellEditorServices.psd1
# Export the signing certificate to a file for import
$sig.SignerCertificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert) > $certPath
# Import the certificate into the machine's cert store
Import-Certificate -FilePath $certPath -CertStoreLocation Cert:\CurrentUser\TrustedPublisher

@rjmholt
Copy link
Contributor

rjmholt commented Jan 9, 2019

Reopening to track shipping a script to do this

@rjmholt rjmholt reopened this Jan 9, 2019
@TylerLeonhardt
Copy link
Member

@Ryoken0367 can you confirm that @rjmholt's script works? Keep in mind, you need to make a small tweak to the path in the example.

@SteveShe
Copy link

SteveShe commented Jan 9, 2019

Nope, it doesn't work and I'm not sure why he thought it would.

PS C:\Users\mydir> $sig.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert) > $certPath
Method invocation failed because [System.Management.Automation.Signature] does not contain a method named 'Export'.
At line:1 char:1
+ $sig.Export([System.Security.Cryptography.X509Certificates.X509Conten ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

@rjmholt
Copy link
Contributor

rjmholt commented Jan 9, 2019

Nope, it doesn't work and I'm not sure why he thought it would.

Sorry, typo: $sig.Export(...) should be $sig.SignerCertificate.Export(...). I've edited the snippet. Try that.

@rjmholt
Copy link
Contributor

rjmholt commented Jan 9, 2019

Also note that this will only work in Windows PowerShell for now, since it depends on the PKI module

@Ryoken0367
Copy link

Sorry all, been super busy the past couple of days; just getting a chance to circle back around to this. Tested the script (after making the path tweak), and getting an error. It seems the certificate it's creating isn't valid.
image
When I open the certificate file I get:
image

@rjmholt
Copy link
Contributor

rjmholt commented Jan 10, 2019

I've looked into this a bit more (above script was a naive attempt to turn a GUI procedure into script).

Here's a script that I've verified works on my machine:

# The signature for the EditorServices module file
$cert = (Get-AuthenticodeSignature ~\.vscode\extensions\ms-vscode.powershell*\modules\PowerShellEditorServices\PowerShellEditorServices.psd1).SignerCertificate
# Get the Cert:\CurrentUser\TrustedPublisher cert store
# IMPORTANT: You may not want CurrentUser here -- change to your needed location
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new("TrustedPublisher", "CurrentUser")
# Open the store
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::MaxAllowed)
# Add the cert to the TrustedPublishers store
$store.Add($cert)

@Ryoken0367
Copy link

That worked, I left it at CurrentUser, since I'm the only user of this computer. No errors, and the integrated console loads without issue now as well.

@rjmholt
Copy link
Contributor

rjmholt commented Jan 11, 2019

After workshopping a good way to trust the MS certificate (the obvious problem being that any PowerShell script to trust the certificate would also be untrusted), it turns out a very simple way is to just interactively import the editor services module and select Always run (verifying that the signing certificate is indeed a Microsoft Corporation one).

So:

ipmo ~/.vscode/ms-vscode.powershell*/modules/PowerShellEditorServices/PowerShellEditorServices.psd1

Then:
accept_cert

@TylerLeonhardt
Copy link
Member

@SydneyhSmith we can doc this workaround in https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode?view=powershell-6

or somewhere in docs.microsoft.com

It could go in our troubleshooting doc in GitHub, but I feel like this would be better in a slightly more official location

@SydneyhSmith
Copy link
Collaborator

@TylerLeonhardt Yeah I'm thinking it should live in docs, we can decide if it should be a sub category or a doc of its own--adding it to my backlog 😄

@SydneyhSmith
Copy link
Collaborator

Closing as this has now been documented MicrosoftDocs/PowerShell-Docs#3612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash.
Projects
None yet
Development

No branches or pull requests