WINDOWS 8 –
POWERSHELL SCRIPT CANNOT BE LOADED BECAUSE RUNNING SCRIPTS IS DISABLED
I just stumbled upon an interesting Technet blog for
Windows scripts here.
Attempting to run a Powershell script however
generated the following error: [See bellow screenshot].
First let’s take a look at the Powershell execution
policies – Restricted is the default
policy and it prevents the running of scripts.
Our other alternatives are:
AllSigned –
Scripts can run but must be signed by a trusted publisher
RemoteSigned –
Scripts can run. Trusted publisher scripts must be signed. Scripts that you
have written yourself do not need to be digitally signed.
Unrestricted –
Unsigned scripts can be run and the user is warned before running downloaded
scripts.
Bypass –
nothing is blocked and there are no warnings or prompts.
For full disclosure on these policies review the
Execution Policies link above.
Choose your alternative Execution Policy carefully –
Restricted is the only policy that can save you from running malicious code
(signed or unsigned) on your system!
Next we need to be aware of the Execution Policy
scopes:
Process –
only affects the current Powershell process.
CurrentUser –
affects only the current user.
LocalMachine –
affects all users on the computer.
So now let’s open up Powershell and review our current
Execution Policy. From the Start screen just type Powershell and click on it in
the search results.
Enter the following command to review the current
policy:
Get-ExecutionPolicy -List
As you can see my default policy is Undefined (which
is the same thing as Restricted):
So now we can change the Execution Policy for the CurrentUser Scope to RemoteSigned.
If you wish to choose a different scope and/or policy then be my guest:
Set-ExecutionPolicy RemoteSigned -Scope
CurrentUser
Note: You will see the
following warning – press Enter to continue: [See the bellow
screenshot].
We
can now check and see that the policy has been changed:
Get-ExecutionPolicy -List
To finally run the
Powershell script I had to run Powershell as an Administrator (right click and
Run As Administrator).
Now enjoy your Powershell
!
No comments:
Post a Comment