Navigating the world of command-line interfaces and scripting can be a smooth experience, especially with powerful tools like PowerShell integrated into Visual Studio Code (VSC). However, it’s not uncommon for developers to hit unexpected roadblocks. One particularly frustrating message that often appears after an npm update or similar package management operations is: “VSC PowerShell. After npm updating packages .ps1 cannot be loaded because running scripts is disabled on this system.” This error effectively halts your workflow, preventing you from executing necessary scripts. It signals a fundamental security measure within PowerShell itself โ its execution policy. Understanding this policy, why it’s in place, and how to safely adjust it is crucial for any developer working with PowerShell scripts in their environment. This guide will walk you through diagnosing and resolving this common issue, ensuring your development environment runs smoothly and securely.
Understanding PowerShell Execution Policies
PowerShell’s execution policy is a critical security feature designed to control the conditions under which PowerShell loads configuration files and runs scripts. Think of it as a gatekeeper, preventing potentially malicious scripts from running without your explicit consent. By default, on most Windows systems, this policy is set to a highly restrictive level, which is why you encounter the “running scripts is disabled” error. This default setting is a proactive measure to protect users from scripts downloaded from the internet or received via email that could harm their system.
There are several types of execution policies, each offering a different level of security and flexibility. The most common ones include:
- Restricted: This is the default policy, and it’s the most secure. It prevents any scripts from running, and PowerShell can only be used in interactive mode. You cannot run .ps1 files, even those you’ve written yourself.
- AllSigned: This policy allows scripts to run only if they have been digitally signed by a trusted publisher. If a script is unsigned, or signed by an untrusted publisher, it will not run. This offers a good balance of security and functionality, especially in corporate environments where scripts are often signed.
- RemoteSigned: This policy is a commonly recommended setting for developers. It allows local scripts (those you create on your own computer) to run without a digital signature. However, scripts downloaded from the internet or shared network locations must be digitally signed by a trusted publisher. This policy helps mitigate risks from external scripts while allowing local development.
- Unrestricted: This policy allows all scripts to run, regardless of their origin or signature. While it offers maximum flexibility, it also carries the highest security risk and is generally not recommended for everyday use, especially on production systems.
- Bypass: No warnings or prompts are given, and nothing is blocked. This policy is primarily used for specific, automated tasks where no user interaction is desired, but it also carries significant security implications.
To fix the error where a .ps1 script cannot be loaded because running scripts is disabled on your system, you generally need to adjust PowerShell’s execution policy. The most secure and common recommendation for developers is to set the policy to RemoteSigned, which permits local scripts to execute while requiring digital signatures for scripts downloaded from the web, thus balancing security with development flexibility. This ensures you can run your own tools and build processes without unnecessary hurdles, while still maintaining a reasonable level of protection against external threats. Understanding these policies is the first step towards resolving the “VSC PowerShell. After npm updating packages .ps1 cannot be loaded because running scripts is disabled on this system” message.
Diagnosing the “Running Scripts is Disabled” Error
When you encounter the specific message “VSC PowerShell. After npm updating packages .ps1 cannot be loaded because running scripts is disabled on this system,” it almost always points directly to your PowerShell execution policy. Visual Studio Code simply acts as the host for the PowerShell terminal, and the underlying PowerShell engine is enforcing its security settings. The npm update command itself doesn’t directly cause this; rather, it often triggers the execution of a .ps1 script (e.g., a post-install script or a build script) that then runs into this policy restriction.
To confirm that the execution policy is indeed the culprit, you can easily check your current setting within PowerShell. Open a new PowerShell terminal within VS Code or directly from your Start Menu. Then, type the following command:
Get-ExecutionPolicy
Press Enter. The output will display your current execution policy. If it shows “Restricted,” then you’ve pinpointed the problem. If it shows “AllSigned” or another policy that still prevents your specific script from running (e.g., if your script is unsigned and from the internet while on “RemoteSigned”), you’ll need to consider how that policy interacts with your script’s origin.
Common scenarios leading to this error include:
- Installing new Node.js packages that include PowerShell scripts in their post-install hooks.
- Running custom build scripts or task runners defined in your package.json that use PowerShell.
- Attempting to use VS Code extensions that rely on PowerShell scripts for their functionality.
- Cloning a repository that contains PowerShell utility scripts for setup or development.
Question & Answer :
I design websites in VSC and PowerShell is my default terminal.
After updating and deploying a website to firebase earlier, I was prompted to update firebase tools - which I did using npm. Immediately after I cannot run/access any firebase scripts wthout the folllowing error:
firebase : File C:\Users\mada7\AppData\Roaming\npm\firebase.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1
firebase + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
I’ve spent a few hours searching around and can’t find a solid answer the problem. Many threads are several years old and I find it bizarre I’ve not had this problem in the past year until today. I can still access firebase scripts if I set my default terminal to cmd.
Assuming the problem was related to firebase-tools I’ve carried on working but have now updated vue.js and get the error again when trying to run any vue commands in powershell:
vue : File C:\Users\mada7\AppData\Roaming\npm\vue.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1
vue + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
VSCode Version: Version: 1.37.1 (user setup) Commit: f06011a Date: 2019-08-15T16:17:55.855Z Electron: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Windows_NT x64 10.0.18362 OS Version: Windows 10 Home Version - 1903 OS build - 18362.295
I’ve been reading around and seen many threads around permissions for scripts, but I haven’t changed any - indeed the PowerShell scripts worked right up until I updated my packages. No other settings touched in the mean time. I don’t want to be changing PowerShell settings unnecessarily.
This is a powershell security policy, to fix it, run Powershell as administrator and run the following
PS C:\> Set-ExecutionPolicy RemoteSigned
If you don’t want to run the command as an administrator but just for the current user, you can add a scope like below
PS C:\> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
The stricter the policy, the more secure your system becomes.
You can change RemoteSigned to other options like: Restricted, AllSigned, RemoteSigned, Unrestricted
Source: https://tecadmin.net/powershell-running-scripts-is-disabled-system/
Alternatively you can modify C:\Program Files\PowerShell\7\powershell.config.json using a text editor and add or modify the following section.
{ .... "Microsoft.PowerShell:ExecutionPolicy": "RemoteSigned" }
You can also run your script without modifying security policies by using the command prompt as noted by ztom’s answer here.