Skip to content
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

PowerShell Integrated Console clarification questions (syntax highlighting and execution policy) #1217

Closed
jeremytbrun opened this issue Feb 28, 2018 · 9 comments

Comments

@jeremytbrun
Copy link

System Details

  • Operating system name and version: Windows 10 (Build 15063.877)
  • VS Code version: 1.20.1
  • PowerShell extension version: 1.6.0
  • Output from $PSVersionTable:
    Name Value

PSVersion 5.1.15063.786
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.786
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:

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

1.20.1
f88bbf9137d24d36d968ea6b2911786bfe103002
x64

Major Minor Build Revision


1 6 0 0
ms-python.python@2018.1.0
ms-vscode.PowerShell@1.6.0
nhoizey.gremlins@0.7.0
robertohuertasm.vscode-icons@7.20.0

Key : PSVersion
Value : 5.1.15063.786
Name : PSVersion

Key : PSEdition
Value : Desktop
Name : PSEdition

Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name : PSCompatibleVersions

Key : BuildVersion
Value : 10.0.15063.786
Name : BuildVersion

Key : CLRVersion
Value : 4.0.30319.42000
Name : CLRVersion

Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion

Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion

Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion

Issue Description

I have two questions about the behavior of the vscode-powershell extension.

  1. How do you set the execution policy for the PowerShell Integrated Console created by the extension? I am able to use terminal.integrated.shellArgs.windows for setting the policy of the default integrated terminal shell, but it does not seem to affect the PowerShell Integrated Console created by the extension.
  2. Why is it that PowerShell syntax highlighting works in the default integrated terminal shell (Get-Process is highlighted yellow, for example), but in the PowerShell Integrated Console created by the extension there doesn't seem to be any syntax highlighting.

Attached Logs

Follow the instructions in the README
about capturing and sending logs.

@dsolodow
Copy link
Contributor

dsolodow commented Mar 8, 2018

The syntax highlighting you refer to is a function of the PSReadLine module which is not yet compatible with the integrated terminal. This is due to change soon though: #535

As far as the execution policy, I'm not aware of a way to set the via VSCode settings, but the integrated console does honor the settings from Set-ExecutionPolicy

If you want the integrated console to use a different policy, I'd probably put it in my $profile.currentUserAllHosts inside an if statement.

@jeremytbrun
Copy link
Author

Thanks for the info @dsolodow.

The default Integrated Terminal does seem to honor Set-ExecutionPolicy when set in an independent PowerShell window, but the "PowerShell Integrated Console" that loads with the vscode-powershell extension does not seem to honor it (see screenshot). It seems to default to "RemoteSigned". When I try to set the policy within the PS Integrated Console it errors (see screenshot).

Somehow the powershell process being kicked off by the vscode-powershell extension seems to be setting a policy of RemoteSigned that cannot be overwritten?

capture1

capture2

@dsolodow
Copy link
Contributor

dsolodow commented Mar 8, 2018

Fascinating. What happens if you run

Set-ExecutionPolicy Unrestricted -Scope Process

@jeremytbrun
Copy link
Author

That seems to work. Hmmm. But why does it default back to RemoteSigned after restarting the PowerShell Integrated Console? Any way to make it default to something else?

capture1

@jeremytbrun
Copy link
Author

It appears it may be configurable by adding the following line of code to Microsoft.VSCode_profile.ps1.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process

Let me know if this is the only way you know of.

Thanks @dsolodow !

@dsolodow
Copy link
Contributor

dsolodow commented Mar 8, 2018

Yeah, adding it to the profile was something I mentioned earlier. :)
I personally avoid using the host specific profiles, so I'd instead add the following to profile.ps1:

If ($host.Name -eq 'Visual Studio Code Host')
{
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
}

@jeremytbrun
Copy link
Author

Thanks. Sorry I didn't make that connection at first. :)

Thanks for the pointer on the general profile script.

@thenning
Copy link

I tried setting the execution policy in the profile for integrated console, but the integrated console won't run the profile script for the exact same reason.

Anyone have any ideas?

@TylerLeonhardt
Copy link
Member

@thenning can you attach your logs so that we can better assist :)

Here's the doc:
https://github.com/powershell/vscode-powershell/#2-capture-verbose-logs-and-send-them-to-us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants