Issue:-
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.
Set-ExecutionPolicy Unrestricted <enter>
3. We can again run “Get-ExecutionPolicy” cmdlet to verify policy level is changed to “Unrestricted”:
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:
1. Use the “Get-ExecutionPolicy” cmdlet to verify policy level:
Get-ExecutionPolicy <enter>
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 <enter>
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 <enter>
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.
No comments:
Post a Comment