PowerShell execution policies are a security mechanism to protect your system from running malicious scripts.
Execution policies are based on trust
Execution policies have various security levels, like:
- Unrestricted – the least restrictive policy is one that does not affect at all; it’s Unrestricted. Unrestricted execution policies are essentially disabled. Users can run all scripts regardless of trust when an execution policy is Unrestricted;
- Bypass – like the Unrestricted type, an execution policy set to Bypass, blocks nothing, while Bypass and Unrestricted have a similar effect, the Bypass execution policy type isn’t technically a type at all. It skips a defined execution policy entirely.
- Undefined – you can essentially remove an execution policy by setting it to Undefined. When you set an execution policy to Undefined, PowerShell completely removes any assigned execution policies from the assigned scope.
To change the PowerShell execution policy on your Windows computer, use the Set-ExecutionPolicy cmdlet.
Type Get-ExecutionPolicy to verify the current settings for the execution policy.
Type Set-ExecutionPolicy RemoteSigned to set the policy to RemoteSigned.
Type Set-ExecutionPolicy Unrestricted to set the policy to Unrestricted.
When all scopes are set to Undefined, PowerShell essentially treats all scopes as Restricted.
The most restrictive execution policy is Restricted.
To ensure all PowerShell scripts are cryptographically signed, set the execution policy to AllSigned.
The RemoteSigned execution policy enforces that all scripts are written somewhere other than your local computer to be cryptographically signed.
You can read more on the official webpage and see the next examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | PS C:\Windows\system32> Set-MpPreference -EnableNetworkProtection Enabled PS C:\Windows\system32> Set-MpPreference -EnableNetworkProtection AuditMode PS C:\Windows\system32> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser Undefined LocalMachine Undefined PS C:\Windows\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine PS C:\Windows\system32> Set-ExecutionPolicy -ExecutionPolicy Restricted -Scope LocalMachine PS C:\Windows\system32> Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser PS C:\Windows\system32> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser AllSigned LocalMachine Restricted PS C:\Windows\system32> Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process PS C:\Windows\system32> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process AllSigned CurrentUser AllSigned LocalMachine Restricted PS C:\Windows\system32> Get-ExecutionPolicy AllSigned |