Windows PowerShell Set-ExecutionPolicy
It comes as a shock to realize that by default, and by design, PowerShell code just won’t execute because of security concerns. Fortunately you can change this behavior easily with Set-ExecutionPolicy.
- Start With Get-ExecutionPolicy
- Execution Policy Values
- Troubleshooting Set-ExecutionPolicy
PowerShell Pre-requisites and Checklist
In the case of Windows 7 and later, you don’t need to download any extra files, just: ‘Add Feature’ –> Windows PowerShell. However, for older operating systems, there are different versions of PowerShell for XP, Windows Server 2003 and Vista. For such legacy systems only, you need to download PowerShell from Microsoft’s site.
Once you have installed PowerShell 2.0 or later, I recommend choosing the ISE (Integrated Scripting Engine) version, it will save buying a text editor.
I like experiments. Get-Execution allows us to take a snapshot before we make any changes with ‘Set’. My other reason for introducing ‘Get’ is to help with troubleshooting why scripts are or are not working.
# PowerShell Check Scripts
RemoteSigned (Guy’s favourite. Local scripts OK)
Unrestricted (Gung-ho setting, useful for testing)
AllSigned (Secure but a pain to setup)
Bypass (Never used)
Undefined (Tricky setting)
Not only is this a job that needs doing so that all your other PowerShell scripts work, but also changing the script execution behaviour gives you valuable experience with the ‘Set’ verb.
# PowerShell Set Script Behaviour
Note : Because all that you get is the message below, you may wish to append this line:
These simple mini PowerShell tutorials will help you to use Get and Set-Executionpolicy to find out where your scripts fail to run.
Help With Set-ExecutionPolicy Parameters
# PowerShell Set-ExecutionPolicy Parameters
Checking the help file may reveal useful parameters, for instance -List may help with troubleshooting, see more below.
While you do all of the above and configure Set-ExecutionPolicy scripts may still not run because of Group Policy restrictions. Here are the factors to consider:
Computer Group Policy > User Group Policy > Process (session) execution policy > User execution policy > Computer execution policy.
# PowerShell Set-ExecutionPolicy List
Get-Help Set-ExecutionPolicy -List
Typical Results From Listing ExecutionPolicies
Summary of Get-ExecutionPolicy
Having to adjust Get-ExecutionPolicy is the price we pay for security, administrator must be allowed to turn off PowerShell code to stop hackers or their viruses gaining control. Set-ExecutionPolicy tackles the specific problem that your PowerShell script will not run. Fortunately if you don’t like this behavior you can change it easily with Set-ExecutionPolicy.
If you like this page then please share it with your friends
See more Windows PowerShell tutorials
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.