Inside of visual studio code, I\'m trying to execute a script.bat from the command line, but I\'m getting the following error:
File C:\\Theses_Repo\\t
Face the same issue and this works for me. open PowerShell as Administrator and paste this.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
I opened VS Code as Administrator and ran this command in the terminal:
Set-ExecutionPolicy Unrestricted
It allowed me to run the scripts without an errors.
This is not a VSCode specific issue, it is a OS one. There are different levels for machine, user, process that allow PowerShell Scripts to run and it must be enabled.
If this is your machine just change the execution policy to RemoteSigned or unrestricted so that is applies to your entire system. If you just want to use it in VSCode, the change your settings file or change you shortcut to include the execution policy you want to use. The Recommendation is RemoteSigned. Meaning all local code will run, but any remote scripts must be signed.
If this is a corporate machine, that has the Execution set to Restricted, then no code will run until that setting is changed. You can still run code by selecting it all in the VSCode editor and hitting F8. Now, if they have enforced this policy, then you need to talk to the IT time to get them to change it for you.
All of this is detailed in the PowerShell Help files.
Get-Command -Name '*executionpolicy*' | ft -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-ExecutionPolicy 3.0.0.0 Microsoft.PowerShell.Security
Cmdlet Set-ExecutionPolicy 3.0.0.0 Microsoft.PowerShell.Security
# get function / cmdlet details
(Get-Command -Name Get-ExecutionPolicy).Parameters
Get-help -Name Get-ExecutionPolicy -Full
Get-help -Name Get-ExecutionPolicy -Online
Get-help -Name Get-ExecutionPolicy -Examples
Get-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Get-ExecutionPolicy -List
(Get-Command -Name Set-ExecutionPolicy).Parameters
Set-help -Name Set-ExecutionPolicy -Full
Set-help -Name Set-ExecutionPolicy -Online
Set-help -Name Set-ExecutionPolicy -Examples
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Set-ExecutionPolicy -ExecutionPolicy Restricted
Invoke-Command -ComputerName "Server01" -ScriptBlock {Get-ExecutionPolicy} | Set-ExecutionPolicy -Force
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy AllSigned -Force
Get-ExecutionPolicy -List
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Undefined
Set-ExecutionPolicy -Scope Process -ExecutionPolicy AllSigned
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Note, if your org is controlling this, the again, talk to them before trying to bypass the policy, because if they did this, this also means they are monitoring it, and if you do this that will know. I have seen things like this engender RPE's. (Resume Producing Events)
Run VS-Code as ADMIN.
This fixed my issue on my home PC with running ng new my-App which had produced this error when I first opened VS-Code from the installation process.
The simplest way to deal with this problem from Visual Studio Code is to change from powerShell to cmd (assuming there's no reason for using powershell in your case). To do so, follow these few steps:
I have not found such solution among current answers. Hope that helps!