PowerShell: How to Change Script Execution Policies

Aidan Palmer
3 min readJan 22, 2023

--

I’ve recently started learning Python by working through the book “Learn Python3 the Hard Way,” and have gotten to the point in the book where I start learning how to run Python scripts within PowerShell (Ch. 46). At this point in the book I was trying to run a script that will activate a virtual environment for use in a later chapter. But when I tried to execute the script, I would get the following error message:

Thankfully the error message is somewhat insightful, and I was able to figure out the solution with some quick Googling. The ability to execute scripts in PowerShell is disabled by default, as a type of security measure so that a user does not accidentally run a malicious script that was downloaded from a shady website. This is an understandable security precaution, but a little annoying for someone like me. There are a few different ways to enable script execution, and I went with the simplest method — a single command in PowerShell.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine

You will then be prompted to confirm these changes, and Microsoft will also insert a brief warning about security risks associated with changing execution policies. Input A (Yes to All).

Now you can execute scripts in PowerShell. There are other options for how to run this command, such as only allowing script execution for a certain user (if you are on a shared machine or domain), or restricting the ability to execute downloaded scripts (versus locally created scripts). One good option is to input RemoteSigned as the Execution Policy, which will only let the user run locally written scripts, but you would have to unblock a downloaded script each time you had to run one. I am comfortable with leaving the Execution Policy on my computer as Unrestricted, but I would most likely use the RemoteSigned option if I were running scripts on a client’s computer for work.

After changing the Execution Policy it is always a good idea to run the following command to make sure the changes you’ve made are correct.

Get-ExecutionPolicy -List

That’s all there is to it. Once you figure out the options you want to input for your scenario, simply type in the command and you can now run your script.

Here are more options for setting the Execution Policy:

--

--

Aidan Palmer
0 Followers

I work in IT and like to write about anything tech-related that I find interesting.