How to Fix Error File or Script is Not Digitally Signed in PowerShell

Introduction

Have you ever run into the following error when trying to run a PowerShell script?

.\file.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.

Execution of scripts is disabled on this system for security reasons. If you need to run a script, you need to change the execution policy.

However, even after changing the execution policy, you may still get the following error:

file.ps1 cannot be loaded because the execution of scripts is disabled on this system.

In this blog post, we will show you how to fix this error so that you can run your PowerShell scripts without any problems.

What Causes The Error?

The error is caused by a setting in the PowerShell execution policy. Now, it’s better to check your current execution policy by executing below script.


Get-ExecutionPolicy

Typically, you get this error because the execution policy is RemoteSigned which means if you want to run a script from local computer, the script must be signed first.

In general, there are some execution policies in PowerShell:

  • Restricted
    This is the default execution policy. It allows you to run commands at the command prompt but disables the execution of scripts.
  • AllSigned
    Scripts can run but must be signed by a trusted publisher. If you run a script by untrusted publisher yet, you will be prompted whether you want to trust the publisher or not.
  • RemoteSigned
    We can run the script on local computer, but any scripts and configuration files from the internet must be signed by a trusted publisher.
  • Unrestricted
    Unsigned scripts can run. If you run a script downloaded from the Internet, you will get a warning saying that this script can potentially harm your computer and asking whether you want to run this script.
  • Bypass
    This policy blocks nothing and displays no warnings or prompts.
  • Undefined
    This policy removes the execution policy from the current scope. If the execution policy in all scopes is Undefined, the effective execution policy is Restricted, which is the default execution policy. The Undefined execution policy will not remove an execution policy that is set in a Group Policy scope.

How To Fix The Error?

Set Execution Policy to ByPass

In order to fix the error, we need to disable default setting by running the following command in PowerShell:


Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

This will temporarily disable the setting for the current PowerShell session and allow us to run unsigned scripts without any problem. Once we have finished running our unsigned scripts, we can re-enable the setting by running the following command:


Set-ExecutionPolicy -Scope Process -ExecutionPolicy Restricted  

Set Execution Policy to Unrestricted

Alternatively, we can set execution policy to Unrestricted.


Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted

Using Unblock-File command

Unblock-File command can be used to unblock the file that is downloaded from internet, even when the execution policy is RemoteSigned.


Unblock-File -Path .\File.ps1

Conclusion

The File is not digitally signed error is caused by default setting in the PowerShell execution policy where it doesn’t allow executing unsigned script. In order to fix the error we can set the policy to ByPass or Unrestricted or by unblocking the file using Unblock-File command.