What does the error "Scripting have been disabled on this system"?

11

I was testing some things from PowerShell ISE to be able to mount scripts.

I realized that while I was running the script without saving the file, the commands were executed normally. However, shortly after saving the file on the desktop, the execution of the file started to generate the following error:

  

The script.ps1 file can not be loaded because the    scripting has been disabled on this system.

     

See "get-help about_si   gning "for more details.   At line: 0 char: 0

But I did not disable anything ...

What "enabling" is Windows talking about? How can I enable running PowerShell scripts in Windows?

    
asked by anonymous 13.07.2017 / 14:09

3 answers

13

This is a Powershell security policy to prevent malicious scripts from running improperly on your system. Therefore, all scripts that are not signed will be blocked from running. That is, the execution policy is as Restricted (which is the default).

You can control these permissions by using cmdlet Set-ExecutionPolicy . And you can check out the current execution policy by using the cmdlet Get-ExecutionPolicy .

PS C:\Users\LINQ> Set-ExecutionPolicy RemoteSigned
PS C:\Users\LINQ> Get-ExecutionPolicy
RemoteSigned

There are several types of permissions you can use with this cmdlet

Restricted

Do not load or run Powershell configuration files and / or scripts .

AllSigned

It only runs scripts and configuration files signed by a trusted provider, even though script has been written by you (local).

RemoteSigned

It is basically the same as the above, but allows you to run local configuration files and / or scripts .

Unrestricted

Loads and runs all configuration files and scripts PowerShell. You may be asked to confirm unsigned scripts.

Bypass

There are no restrictions.

Undefined

Removes the current execution policy. Unless it is defined in a group policy.

    
13.07.2017 / 14:17
7

By default the script privilege is Restricted , ie no script called via file can be executed only in interactive mode (via console or ISE)

To change the execution policy use the cmdlet and any of the following

Set-ExecutionPolicy AllSigned 

Restricted : Default value (Windows 8, Windows Server 2012, and Windows 8.1), does not allow any files to be executed this includes configuration files (.ps1xml), modules (.psm1), and .ps1

AllSigned : Allows the execution of files, but requires that the files be signed by a trusted publisher.

Unrestricted : Unsigned scripts can run.

Bypas : Nothing is blocked and does not issue warnings or prompts (ask if you want to execute something for example)

Undefined : Sets the policy to run indefinitely. If all scopes are Undefined by default it becomes Restricted . You can check the different levels with:

Get-ExecutionPolicy -list

Recommended reading:

Set-ExecutionPolicy

About Execution Policies

    
13.07.2017 / 14:17
0

You can also change values via registry key ( regedit or command reg in cmd ):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\ShellIds\Microsoft.PowerShell]
"ExecutionPolicy"="bypass"

Save the above lines as liberar.reg , and open, or use the command reg import liberar.reg

    
17.09.2018 / 20:38