14

I started using Visual Studio Code for Powershell scripting. I'd like to turn off the check for unsigned code, but cannot find out how to do this. I have not found anything in the forums either.

TessellatingHeckler
  • 24,312
  • 4
  • 40
  • 77
Ryan Schoenhard
  • 157
  • 1
  • 1
  • 3

5 Answers5

16

you can adjust the policy by adding arguments to the powershell.exe command. for this, open the settings json file. then add the following line:

    "terminal.integrated.shellArgs.windows": "-ExecutionPolicy ByPass",
user287107
  • 9,046
  • 1
  • 29
  • 47
15

I solved by setting the policy as :

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned

to the Visual code integrated environment running as administrator.

The following blog clearly lists the steps to solve it:

http://donovanbrown.com/post/Using-PowerShell-in-VS-Code

d219
  • 2,503
  • 5
  • 27
  • 33
Enzo
  • 148
  • 1
  • 6
10

PowerShell's default settings help prevent malicious scripts from being run. By default you should / can run scripts on the VSCode integrated terminal.

To change PowerShell security settings open PowerShell with admin privileges and run the command:

Get-ExecutionPolicy -List

You should get a response like this:

        Scope ExecutionPolicy
    ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       RemoteSigned  
 LocalMachine       AllSigned

The CurrentUser is probably Undefined as well since you can't run scripts on your VSCode terminal.

To change that, run this command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Reopen the VSCode Terminal, it should be working now.

If you want more details, you can find a full docs here: https://docs.microsoft.com/es-es/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7

somebadhat
  • 734
  • 1
  • 5
  • 17
Arias.Dev
  • 111
  • 2
  • 6
2

You would use the command Set-ExecutionPolicy to change the execution policy of your system. You'll need to do so from an administrative session. You can find the appropriate syntax by using the command help Set-ExecutionPolicy from a PowerShell prompt.

You can also find command references online, for example SS64 and Technet.

There's also a highly visible Q&A here on Stack Overflow with the same info.

YetAnotherRandomUser
  • 1,217
  • 3
  • 13
  • 29
  • I tried. here is what I got back:PS C:\Users\admrschoenhard\Desktop> Set-ExecutionPolicy undefined PS C:\Users\admrschoenhard\Desktop> c:\Users\admrschoenhard\Desktop\Untitled-1.ps1 – Ryan Schoenhard Nov 02 '17 at 14:38
  • import-module : File \\us.aegon.com\ait\dsst\Powershell\Modules\Bluecat.psm1 cannot be loaded. The file \\us.aegon.com\ait\dsst\Powershell\Modules\Bluecat.psm1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. At C:\Users\admrschoenhard\Desktop\Untitled-1.ps1:1 char:1 + import-module \\us.aegon.com\ait\dsst\Powershell\Modules\Bluecat.psm1 – Ryan Schoenhard Nov 02 '17 at 14:39
  • + CategoryInfo : SecurityError: (:) [Import-Module], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand – Ryan Schoenhard Nov 02 '17 at 14:39
  • Quick note - When I pull out the import-module statement it allows me to set the execution policy to undefined. It's only when trying to import the unsigned module that I get the error that I can't set the policy to unsigned. – Ryan Schoenhard Nov 02 '17 at 14:45
  • It looks like I misunderstood what you were trying to do. Disabling unsigned scripts is something you can do in an administrative interactive shell. I think it would defeat the purpose of the command if you could just put that in any and all scripts. As for Visual Studio Code, what happens when you try to use the PowerShell IDE? Edit your question to include your existing code and the output errors. It's painful here in the comments. Blueshell looks like a professional package, but I was not able to find a page with the psm1 file. What do their direction say about installing it? – YetAnotherRandomUser Nov 03 '17 at 15:06
1

Go to Select default shell

enter image description here

then select Command prompt instead of Windows power shell it will work

enter image description here

harsha kumar Reddy
  • 1,071
  • 1
  • 16
  • 30