The Computer Oracle

How to enable execution of PowerShell scripts?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island

--

Chapters
00:00 Question
00:39 Accepted answer (Score 650)
01:14 Answer 2 (Score 137)
01:37 Answer 3 (Score 93)
01:59 Answer 4 (Score 35)
03:09 Thank you

--

Full question
https://superuser.com/questions/106360/h...

Accepted answer links:
[Running Scripts]: http://technet.microsoft.com/en-us/libra...

Answer 2 links:
[restricted]: https://docs.microsoft.com/en-us/powersh...
[Get-ExecutionPolicy]: https://docs.microsoft.com/en-us/powersh...
[Set-ExecutionPolicy]: https://docs.microsoft.com/en-us/powersh...
[unrestricted]: https://docs.microsoft.com/en-us/powersh...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#powershell

#avk47



ACCEPTED ANSWER

Score 713


  1. Start Windows PowerShell with the "Run as Administrator" option. Only members of the Administrators group on the computer can change the execution policy.

  2. Enable running unsigned scripts by entering:

    set-executionpolicy remotesigned
    

This will allow running unsigned scripts that you write on your local computer and signed scripts from Internet.

See also Running Scripts at Microsoft TechNet Library.




ANSWER 2

Score 159


The Default Execution Policy is set to restricted, you can see it by running Get-ExecutionPolicy:

Get-ExecutionPolicy

Run Set-ExecutionPolicy like this to switch to the unrestricted mode:

Set-ExecutionPolicy unrestricted



ANSWER 3

Score 113


On my machine that I use to dev scripts, I will use -unrestricted as above. When deploying my scripts however, to an end user machine, I will just call powershell with the -executionpolicy switch:

powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1



ANSWER 4

Score 11


Depending on the Windows version and configuration, you may have the following warning, even in Unrestricted mode:

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this
script can potentially harm your computer. If you trust this script, use the 
Unblock-File cmdlet to allow the script to run without this warning message. 
Do you want to run?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D")

The solution is to use the "bypass" policy, enabled with the following command:

Set-ExecutionPolicy Bypass

From the documentation:

Bypass: Nothing is blocked and there are no warnings or prompts.

This is obviously insecure, please understand the risks involved.