Script Execution Policy

Set the script execution policy to control the script execution behavior.

In PowerShell, there are cases where scripts cannot be executed by default (Restricted) due to security reasons.
Therefore, if you want to execute the script, you need to change the execution policy.
You can also specify the scope when changing the execution policy.

Microsoft Docs
About Execution Policies

Example: Changing the script execution policy

An example where an error occurs in the Restricted state,
the execution policy of the current user is changed to RemoteSigned,
and the script is executed.

PS C:\Users\user\Desktop> Get-ExecutionPolicy
PS C:\Users\user\Desktop> .\script.ps1
# Error occurs
PS C:\Users\user\Desktop> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\Users\user\Desktop> Get-ExecutionPolicy
PS C:\Users\user\Desktop> .\script.ps1

Temporarily change the execution policy

When executing PowerShell, you can temporarily change the execution policy by adding -ExecutionPolicy.

cmd> powershell script.ps1
# Error occurs
cmd> powershell -ExecutionPolicy RemoteSigned .\script.ps1
cmd> powershell .\script.ps1
# Error occurs


Last modified October 11, 2022: update (8216439)