vscode-powershell: Cannot run PowerShellEditorServices when execution policy is set to AllSigned
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.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 82 (9 by maintainers)
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:
Then:
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.
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:
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:
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!
Thanks for the detailed explanation, everyone!
It sounds like we need to take one of two paths:
Did I miss something?
I’ve managed to get Visual Studio Code working under AllSigned.
I don’t know how it had not struck me earlier but as @rkeithhill said earlier everything that needs to be signed is signed. So we do
Get-AuthenticodeSignature<full path>\Start-EditorServices.ps1 | select *and see thisMicrosoft Code Signing PCA 2011 is not on my machine’s Trusted Root Certification Authorities list. Googling
Microsoft Code Signing PCA 2011leads me to knowing that this certificate is distributed along with Visual Studio itself and the necessary file is name “manifestSignCertificates.p12”. There’s a mention in this guide that one needs to install a number of certificates for Visual Studio offline installation.This article mentions being able to download Visual Studio installation files doing this
vs_community.exe --layout C:\vs2017offline --lang en-USas I hadn’t managed to find the certificates anywhere else (maybe they’re here on github somewhere).So I get out this “manifestSignCertificates.p12” and double-click it ‘nexting’ it to my Trusted Root CAs. But in order to launch scripts under either RemoteSigned or AllSigned you need to trust both a root CA and a certificate issuer so then when I manually start
.\Start-EditorServices.ps1I still get a warning that Microsoft is not a Trusted Issuer. But! If you hit [A] to always launch scripts signed by that issuer its certifcate gets intoCert:\CurrentUser\TrustedPublisherand the script runs just fine. So VS Code now works as expected.And this whole situation leads me to citing myself:
Sorry for a bit broken English.
Ran into some information that might be helpful for this.
When AuthorizationManager calls out to SecuritySupport to get the execution policy it iterates scopes until it gets to one that isn’t
Undefined. The order it iterates is here. Unfortunately both policy scopes come before theProcessscope, meaning we have no way of overriding this.The message from the exception being thrown means an exception was that wasn’t expected.
The
AuthorizatonManagercalls host API’s when a file is considered remote. I know the entry script itself doesn’t show as remote, but maybe something else does.My guess is the problem is with the PSES host, it’s possible the prompt handlers aren’t fully initialized by the time the
AuthorizationManagertries to call them. I’m not able to look into this much further than that, but hopefully that helps.The bigger problem is that even if this is just a host problem, and that gets fixed, using VSCode in all signed would be a pain.
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!
@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
@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:
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 🎉