Cannot be loaded because running scripts is disabled on this system windows 10 PowerShell

Here is the error message: your script name cannot be loaded because running scripts is disabled on this system.

Full error message:

PS C:\Users\codetryout\Documents> .\my-script.ps1
.\my-script.ps1 : File C:\Users\codetryout\Documents\my-script.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.
At line:1 char:1
+ .\my-script.ps1
+ ~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\codetryout\Documents>

Solution for PowerShell cannot be loaded because running scripts is disabled on this system

If you see this error when you try to run a PowerShell script, you can follow the below steps.

  • Go to Windows Start Menu
  • Type Powershell
  • From the listing Right click on the Powershell
  • Run as Administrator
  • Once the Powershell window is opened, set the below execution policy as shown below
Set-ExecutionPolicy RemoteSigned
  • Select A when prompted. ([A] Yes to All)

Demo to set PowerShell RemoteSigned Execution Policy :

PS C:\> 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
http://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"): A
PS C:\>

Make sure to revert the policy, after you are done

To change the execution policy back to restricted mode, Open the PowerShell as admin again as described above and run,

Set-ExecutionPolicy Restricted

Demo to set PowerShell Restricted Execution Policy:

PS C:\> Set-ExecutionPolicy Restricted

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
http://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"): A
PS C:\>

Note: This is for your information purpose only, if you make any changes as administrator, ensure that you have the ownership of the system to do so.