Skip to main content

Changes the user preference for the PowerShell execution policy.

#
# Running unsigned PowerShell scripts from remote computers requires changing the
# execution policy for PowerShell. To determine the current execution policy
# setting, launch a PowerShell window and at the prompt enter `Get-ExecutionPolicy -List`
# to identify the current execution policy setting.
#
# | Execution Policy |                                                                        Description                                                                         |
# |------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
# | Restricted       | No scripts are allowed. This is the default setting, so you will see it the first time you run the command.                                                |
# | AllSigned        | You can run scripts signed by a trusted developer. With this setting in place, before executing, a script will ask you to confirm that you want to run it. |
# | RemoteSigned     | You can run your own scripts or scripts signed by a trusted developer.                                                                                     |
# | Unrestricted     | You can run any script you want.                                                                                                                           |
#
# Resources:
#
# Set-ExecutionPolicy Docs:
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6
#
# 15 Ways to Bypass the PowerShell Execution Policy:
# https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/
#
# Meet PowerShell Tutorial:
# https://blog.netwrix.com/2018/02/21/windows-powershell-scripting-tutorial-for-beginners/
#

#
# To list current execution policies by scope:
Get-ExecutionPolicy -List

#
# To show execution policy of the current user:
Get-ExecutionPolicy CurrentUser

#
# To set the execution policy of the current user to Unrestricted (`-Force` - suppresses all prompts):
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force

# To bypass the ExecutionPolicy - nothing is blocked and there are no warnings or prompts:
PowerShell.exe -ExecutionPolicy Bypass -File .runme.ps1

#
# Set-ExecutionPolicy Scopes:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope MachinePolicy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope UserPolicy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process