How to Fix PowerShell Says “execution of scripts is disabled on this system”

After installing Starship on a fish shell, I thought, why not tweak PowerShell with Starship to give a new look to PowerShell, which had been waiting for a long time for something new.

And that’s the reason I started the procedure to install Starship on PowerShell, but when I launched the terminal to see how it looks after installing Starship instead of getting something new, I found an error that states: “execution of scripts is disabled on this system”.

Well, this error is not new to me, so I solved the error in a minute, but this may not be new to others. That’s the reason I have come up with this short guide to resolve the execution of scripts that are disabled by default on the system to protect it from executing malignant scripts.

FIX: Execution of Scripts is Disabled on this System

The above error is very easy to solve. You just need to run the command, which I will share with you in this article, and I believe you have administrative privileges to follow this article. Otherwise, you won’t be able to change the policy.

Why did the error occur?

By default, Windows doesn’t allow you to run or execute a script that is not signed to prevent your system from any unwanted behaviour that can cause problems for your system.

That security layer is beneficial if you have downloaded or copied some scripts from public space and you don’t know what the script is going to do apart from the primary task.

To find the default execution policy that is defined for your system, you can use the Get-ExecutionPolicy-List cmdlet. The output of the above cmdlet consists of scope and execution policy like the below snippet.

Administrator in C:\WINDOWS\system32
❯ Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    Unrestricted

And to change that policy, you have to use the Set-ExecutionPolicy cmdlet, which will allow you to change the policy by using the following verbs or options: Unrestricted, RemoteSigned, AllSigned, Restricted, Default, Bypass, Undefined.

After understanding why and how the error occurred, let’s see how to resolve the following error using the Set-ExecutionPolicy cmdlet in the next section of this article.

To fix error run Set-ExectutionPolicy cmdlet

I’ll make it simple for you to understand the steps.

  • First, open PowerShell as an administrator.
  • Then, run the command that is given below.
Set-ExecutionPolicy RemoteSigned

Once you execute the command you will get the following option like in the below image simply you can press Y to accept the new policy one by one or A to accept all the changes at once.

Update Policy, press A or Y
Update Policy, press A or Y

After making the changes, you will not be presented with any kind of confirmation, so to get confirmation of our changes, execute the Get-ExecutionPolicy command to check the current policy for your local machine.

The behaviour of the above command

Administrator in C:\WINDOWS\system32
❯ Get-ExecutionPolicy
RemoteSigned

Once you have updated the policy restart the shell to see whether the above-mentioned error is resolved. If still, the problem persists, then execute another command which is given below.

Set-ExecutionPolicy Unrestricted

After that, restart the PowerShell to execute the script that was giving the error.

That’s all it takes to resolve the above mentioned error. If you want to learn more about the execution policy, then do check the following documentation.

If you want to know how to sign your script, then check out this resource.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments