Powershell execution of scripts is disabled on this system

Issue:-


First time when you launch PowerShell and try to run any PowerShell scripts file, it will not run and gives the below error. Here I am trying to run a simple ps script “directory.ps1” with Get-Chitditem cmdlet inside it.

“File C:\ZAid\Testing\Script.ps1 cannot be loaded because the execution of scripts is disabled on this system. “


When PowerShell is first installed the default execution policy is “Restricted.” This means PowerShell will not run scripts or configuration files. Here is a list of policy levels:

·         Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.

·         AllSigned – Only scripts signed by a trusted publisher can be run.
·         RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.
·         Unrestricted – No restrictions; all Windows PowerShell scripts can be run.
Resolution:-

To get out of this issue we need to follow below steps:-

1. Use the “Get-ExecutionPolicy” cmdlet to verify policy level:

Get-ExecutionPolicy

2. What is your policy set at; the execution policy should be set to anything other than “Restricted.” And as we know No PS Scripts can be run if Execution policy is restricted. So we need to change the policy to “Unrestricted” as below:

                  Set-ExecutionPolicy Unrestricted

It will ask for the confirmation, type “Y” to confirm

3. We can again run “Get-ExecutionPolicy” cmdlet to verify policy level is changed to “Unrestricted”:


Get-ExecutionPolicy

4. Now that the policy is set to run scripts, you can go ahead and run the ps script as below.

**Note **
If your machine is 64 bit then open the x86 instance of PowerShell and Set the execution policy to “Unrestricted” as above.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s