Q: How can I get the current PowerShell execution policy setting on my Windows machine? How can I modify this setting? Is there an easy way I can temporarily bypass the execution policy in a current PowerShell session?
A: To get the current PowerShell execution policy, you can simply type Get-ExecutionPolicy at the PS prompt, as Figure 1 shows.
To look at all the execution policies and scopes, you can use the Get-ExecutionPolicy cmdlet with the -list parameter. This command's results are also shown in Figure 1. If you're unfamiliar with the various execution policies and scopes, see "Use Execution Policies to Control What PowerShell Scripts Can Be Run."
To change the execution policy, you can use the Set-ExecutionPolicy cmdlet. For example, to change it to Unrestricted, you'd run command:
To get the execution policy that's set for a particular scope, you must use Get-ExecutionPolicy cmdlet with the -scope parameter.
When running an administrative script, administrators sometimes bypass the execution policy by changing the execution policy to Unrestricted before running the script, then changing the policy back to Restricted after the script runs. The risk here is that an administrator might forget to return the system to the "higher protection" state when done. A safer way to relax the execution policy for your current PowerShell session is to use the Bypass parameter, as follows:
Note that to change the execution policy for the local computer in Windows Vista and later versions, you must start PowerShell with administrator privileges (i.e., use the Run as administrator option).