While running PowerShell script, if you get running scripts is disabled on this system, it is because the PowerShell execution policy is set up by default as Restricted and doesn’t allow to run script.
It throws an exception message as “
cannot be loaded because running scripts is disabled on this system“
PowerShell Scripts Disabled error message as below
.\Get-Printers.ps1: File CL\Get-Printers.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170
PowerShell has built-in security features implemented. PowerShell Execution policy is a safety feature which controls the conditions to run scripts and load configuration. Execution Policy in PowerShell is setup to avoid running malicious scripts in your system.
In this article, I will explain different ways to fix file cannot be loaded because running scripts is disabled on this system.
Let’s understand how to enable execution of running PowerShell script using different execution policies.
Solution: Running scripts is disabled on this system
PowerShell Execution Policy in Restricted mode avoid running script to ensure safety.
Cool Tip: Use
Get-ExecutionPolicy to know default policy applied on your system.
Using RemoteSigned Execution Policy
RemoteSigned execution policy is more secure option. On enabled, it allows local scripts to run. All other scripts from outside requires signed by a trusted publisher.
- Set up RemoteSigned execution policy
- Allows to run local script.
- Now if you try to run .ps1 file, it wont give you running script is disabled on this system error.
Cool Tip: How to fix script is not digitally signed error in PowerShell!
Using UnRestricted Execution Policy
UnRestricted is the default execution policy set up on non-windows system. If you enabled this policy on system, PowerShell can run any unsigned script file.
You can change execution policy using Set-ExecutionPolicy cmdlet.
- Warns the administrator about policy change and security risk associated with UnRestricted mode.
- If you select option, Y or Yes to All, it will apply policy.
- After setting up UnRestricted execution policy, if you try to run ps1 file, it wont give running script is disabled on system error.
Cool Tip: How to use multiline command in PowerShell!
Using ByPass Execution Policy
Using bypass execution policy, nothing is blocked and if you try to run script, it wont give your warning or prompts for confirmation.
With ByPass policy, scripts run temporary with lower security.
powershell -executionpolicy ByPass -File .\Get-Printers.ps1
- runs ps1 script file with lower security for and executes it.
- Once your close PowerShell session, it will also closed ByPass with it.
Using PowerShell ISE
If you don’t want to set execution policy and still want to run script inside ps1 file, best work around is to open script file in PowerShell ISE.
Select all the code in script and hit F8 button to execute script.
Note: Don’t use F5 for execution, else it will try to run ps1 file and throws file cannot be loaded error.
This way, you wont require any permissions or any kind of running script is disabled on this system error.
Cool Tip: How to add a newline to string or variable in PowerShell!
I hope above article to fix file cannot be loaded because running scripts is disabled on this system error using set-executionpolicy helpful to solve your problem.
Use RemoteSigned execution policy to avoid running any malicious scripts or if script is local then open PowerShell script and select all code and hit F8 to execute it.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.