Cyberithub

Powershell(v5) – Running scripts is disabled on this System

Advertisements

In this article, we will talk about the error Running scripts is disabled on this system. PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the execution of malicious scripts.

Powershell(v5) – Running scripts is disabled on this system

Powershell(v5) – Running scripts is disabled on this system

Also Read: How to Format PowerShell command output as List

This error "Running scripts is disabled on this system" comes when the PowerShell execution policy doesn’t allow us to run scripts. On a Windows computer you can set an execution policy for the local computer, for the current user, or for a particular session. You can also use a Group Policy setting to set execution policies for computers and users.

Execution policies for the local computer and current user are stored in the registry. You don't need to set execution policies in your PowerShell profile. The execution policy for a particular session is stored only in memory and is lost when the session is closed. Let's try to understand further about this error "Running scripts is disabled on this system".

The execution policy isn't a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally.

You will not observe this error "Running scripts is disabled on this system" on non-windows computers as on non-Windows computers, the default execution policy is Unrestricted and cannot be changed. The Set-ExecutionPolicy cmdlet is available, but PowerShell displays a console message that it's not supported. Before we look at the error "Running scripts is disabled on this system", we need to understand the types of execution policies.

Windows PowerShell has four different execution policies:-

Restricted -

  • The default execution policy for Windows client computers. This policy generates the error "Running Scripts is disabled on this System"
  • Permits individual commands, but does not allow scripts.
  • Prevents running of all script files, including formatting and configuration files (.ps1xml), module script files (.psm1), and PowerShell profiles (.ps1).

AllSigned -

  • Scripts can run.
  • Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
  • Prompts you before running scripts from publishers that you haven't yet classified as trusted or untrusted.
  • Risks running signed, but malicious, scripts.

RemoteSigned -

  • The default execution policy for Windows server computers.
  • Scripts can run.
  • Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the internet which includes email and instant messaging programs.
  • Doesn't require digital signatures on scripts that are written on the local computer and not downloaded from the internet.
  • Runs scripts that are downloaded from the internet and not signed, if the scripts are unblocked, such as by using the Unblock-File cmdlet.
  • Risks running unsigned scripts from sources other than the internet and signed, but malicious, scripts.
  • This is policy we need to set to avoid the error "Running scripts is disabled on this system"

Unrestricted -

  • The default execution policy for non-Windows computers and cannot be changed.
  • Unsigned scripts can run. There is a risk of running malicious scripts.
  • Warns the user before running scripts and configuration files that are not from the local intranet zone.

 

There are certain scenarios in which you can follow the steps, verify that Execution Policy is set correctly, and still have your scripts fail.

If this happens to you, you are probably on a 64-bit machine with both 32-bit and 64-bit versions of PowerShell, and the failure is happening on the version that doesn't have Execution Policy set. The setting does not apply to both versions, so you have to explicitly set it twice.

NOTE:

Please make sure to start the Powershell with the administrative access before running below steps.

Step 1: Check the Version of Powershell

Check the version of PowerShell before changing the execution policy:-

PS C:\Windows\system32> Get-Host | Select-Object Version

Version
-------
5.1.18362.145

 

Step 2: Enable the Execution policy

Enable the execution policy using below PowerShell command:-

PS C:\Windows\system32> set-executionpolicy remotesigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y

 

Step 3: Check the Execution Policy

After enabling the execution policy, check once the status.

PS C:\Windows\system32> Get-ExecutionPolicy
RemoteSigned

 

For more info on Powershell, Go to: Powershell 5.1

Leave a Comment