By default Powershell execution policy is set to restricted, which prevents execution PowerShell scripts and protects from running malicious scripts.
1) Check Current PowerShell Execution Policy
You can verity your execution policy by running the following command
You can also list all Powershell execution policies by running the following command:
1 2 3 |
>Get-ExecutionPolicy Restricted |
1 2 3 4 5 6 7 8 9 |
>Get-ExecutionPolicy -list Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser Undefined LocalMachine RemoteSigned |
2) Set PowerShell Execution Policy
You can change Powershell execution policy by running the Set-ExecutionPolicy command
1 2 3 4 5 6 |
>Set-ExecutionPolicy -ExecutionPolicy RemoteSigned 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 https:/go.microsoft.com/fwlink/?LinkID=135170. 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"): A |
There are number of different execution policies that you can change. Before changing default execution policy it’s recommended to get familiar with different types of execution policies and what impact have on security.
Execution Policy |
|
Unrestricted |
No restrictions; all Windows PowerShell scripts can be run. |
RemoteSigned |
Downloaded scripts must be signed by a trusted publisher before they can be run. |
AllSigned |
Only scripts signed by a trusted publisher can be run. |
Restricted |
No scripts can be run. Windows PowerShell can be used only in interactive mode. |
Default |
Return execution policy to normal. (Restricted) |
Bypass |
Nothing is blocked and there are no warnings or prompts. |
Undefined |
Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope. |
3) Changing Powershell Execution Policy for specific scope
To change execution scope for specific scope enter the following command:
1 2 3 |
set-ExecutionPolicy -Scope:process Unrestricted Set-ExecutionPolicy -Scope:CurrentUser -ExecutionPolicy:Unrestricted |
4) Unblocking Downloaded Powershell files
All downloaded Powershell files from internet are blocked by default. By running the command below unblocks the file and allow execute even Powershell execution policy is set to RemoteSigned
1 |
>Unblock-File -Path .\Get-RemoteProgram.ps1 |
Leave A Comment