
Originally published on ITBlogPros.com
If you are new to Powershell then you are probably ready to dive in and start experimenting with scripts and all kinds of cool learning resources. If you ever download a script from an external source then you need to be aware of a few things. The first thing to remember is that there is a legitimate safety concern to running scripts, especially if you do not know the source.
You also need to make sure that you understand what each script does before you run it. Powershell is a very powerful tool, and like any tool it will do what it is told, no exceptions. (We take no responsibility for any loss or damage that you might incur by bypassing the execution policy)
So with that out of the way, lets look at what the execution policy is in the first place.
Powershell Execution Policy Overview
Time for a little explanation. The execution policy is a built in setting that decides whether your system can run Powershell scripts in the first place. The standard condition that a new Powershell environment is set to is “restricted”, which is a nice way of saying that Powershell script execution is disabled.
Now don’t be fooled, this isn’t purely a security control. The reason that this is the case is that there are so many easy ways to sidestep the execution policy with just a few simple operations. If this was a legitimate safety then it would require much more work to disable.
The execution policy is more of a preference that can be controlled by your system administrators if they deem it to be necessary than a safety setting.
Uses for Bypassing the Execution Policy
There are tons of reasons why you might want to bypass the execution policy on your local computer, but the main one is so that you can run scripts. Let’s look at a few ways to check your current execution policy settings, and how you can bypass them to get some Powershell work done.
Let’s Check out our Execution Policy
Now that we have decided that we would like to try out a few scripts we need to check if we are even able to run any of them in Powershell. To do this we have to run a cmdlet called Get-ExecutionPolicy.
Our result say’s ‘Restricted’. Hmmm, that’s not good. Let’s see how restricted we are by looking at all of the ways that it has been applied to our system. Each tier of the system hierarchy or Scope has its own execution policy status. We can choose which one we would like to set to unrestricted.
Let’s check by typing this command:
get-executionpolicy -list
The easiest way to run a script is by adding the following to your path when executing it, where the script is named myscript.ps1
Powershell.exe -ExecutionPolicy Bypass -File myscript.ps1
And That’s It!
That’s the easiest way to run your script without running into any warnings or blockers.