Warning: Undefined array key "is_rate_editable" in /home/vhosts/itexperience.net/httpdocs/wp-content/plugins/wpdiscuz/class.WpdiscuzCore.php on line 1303
Fix File cannot be loaded because running scripts is disabled on this system in Powershell - itexperience.net

Fix File cannot be loaded because running scripts is disabled on this system in Powershell

When you try to run a Powershell script (ps1), you may face error File cannot be loaded because running scripts is disabled on this system. This error may appear in Powershell, but also in ISE or Visual Studio Code (VS Code).

File cannot be loaded because running scripts is disabled on this system

This blog post explains:

  • why you get this error.
  • what your options are to keep Powershell safe.
  • how to fix it.

In a hurry? It’s not necessary to read the reason for this error. You may immediately skip to Fixes to File cannot be loaded because running scripts is disabled on this system

Cause

Powershell has built-in security features. One of them is the so-called Execution Policy. This policy can prevent scripts from running and can become useful in certain situations. For instance, in high-secure environments where running unknown Powershell scripts may be risky.  To view the current systemwide Execution Policy setting, type the following in Powershell:
Get-ExecutionPolicy

4 levels of security

Before you focus on fixing, it’s good to know the options. It may save you from using a risky or insecure setting. There are 4 policy levels to choose from. From most secure to most insecure:

  • Restricted: No Powershell scripts can be run. This is the default setting.
  • AllSigned: Scripts can be run, but all must have a digital signature. Even if you wrote the script yourself on the local computer.
  • RemoteSigned: Locally-written scripts can be run. But scripts from outside (email, IM, Internet) must be signed by a trusted publisher.
  • Unrestricted: Any script will run. Regardless of who created them or whether they are signed. 

In the fixes, I assume you have downloaded the script. Thus, I provide the Unrestricted option in each solution. But if you wrote the script yourself on your current pc, you’re better off using RemoteSigned.

Fixes to File cannot be loaded because running scripts is disabled on this system

There are several ways to fix the error “File cannot be loaded because running scripts is disabled on this system.” Each has its pros and cons. But whatever option you choose, it takes care of your problem anyway.
As I noted in 4 levels of security, Unrestricted is always a solution, but RemoteSigned is a more secure option.
All fixes are OS independent. They will work on Windows 10, Windows 2016, Windows 2019. And even on Windows 7.

Set ExecutionPolicy on computer (requires administrator privileges)

To set the ExecutionPolicy for all users on your computer:

    1. Open Powershell as Administrator
      open powershell as administrator
    2. Type Set-ExecutionPolicy Unrestricted and hit Enter.
      set-executionpolicy to unrestricted
    3. Confirm the Execution Policy Change by typing ‘Y‘ and hit Enter.click Y to confirm executionpolicy
    4. Done! Everyone on the computer should now be able to run the script.executionpolicy set to unrestricted


 

Note: once you have set the Execution Policy, it applies to all Powershell sessions in all applications. Do you use Visual Studio Code or Powershell ISE? The new setting also applies to those apps!

Set ExecutionPolicy on user

You don’t have Administrator privileges on your computer? You can still set the ExecutionPolicy to Unrestricted on the scope of the user. Here’s how:

  1. Open Powershell.
  2. Type Set-ExecutionPolicy Unrestricted -Scope CurrentUser and hit Enter.
  3. Confirm the Execution Policy Change by typing ‘Y‘ and hit Enter.
  4. Done! Your user account should now be able to run the script.

Run a Powershell session with ExecutionPolicy Bypass

To lower the security of Powershell for one time only, you can use the Bypass switch. This allows you to run a script temporarily while keeping the stricter settings for all other Powershell sessions.

  1. Open a command prompt.
  2. Type PowerShell -ExecutionPolicy Bypass and hit Enter.
    Powershell loads inside the cmd with lowered security.
  3. Navigate to the path of your script and run it.
  4. Once you close the Powershell window, the Bypass is closed with it.

Run the script in Powershell ISE (or Visual Studio Code)

This is not really running the script. Instead, I would call it the perfect work-around to bypass your strict (company’s) execution policy 🙂
In Powershell ISE, it’s possible to open a script. You are then able to view the code in the editor. Instead of running the ps1, do the following:

  1. select all code in the script.
  2. hit F8 to run the selected code.

This way you don’t need extra permissions to get your work done.

powershell ise run selection

View current ExecutionPolicy level

To view your current ExecutionPolicy, system-wide, type:
Get-ExecutionPolicy

But there are more ExecutionPolicy scopes to view. Type:
Get-ExecutionPolicy -list

This shows you:

  • MachinePolicy (defined by your system administrator).
  • UserPolicy (also defined by your system administrator)
  • Process (Bypass, when run as PowerShell -ExecutionPolicy Bypass)
  • CurrentUser (when Executionpolicy was set with -Scope CurrentUser)
  • LocalMachine (when Executionpolicy was set without extra arguments)

Back to 2008

In 2008, I wrote a similar blog post about the execution policy in Powershell. In Powershell v2, the error code was different:
File cannot be loaded because the execution of scripts is disabled on this system error
Powershell v3 and later had new capabilities. And changed the error to File cannot be loaded because running scripts is disabled on this system.

4.6 8 votes
Article Rating
Subscribe
Notify of
guest
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Yaseen Arafat

Thanks a lot, I rid of at last…

Jonathan

Quick and concise! Thank you so much for this!

Suangpi

Thank you so much!

Ashish Kumar Varma

Thanks Man

Zexy

Thank You T-T !!!! May God bless you Man !!!

opa

THANK YOU

6
0
Would love your thoughts, please comment.x
()
x