How to Set Execution Policy to Unrestricted in PowerShellPowerShell is a powerful command-line tool used by system administrators to manage and automate tasks. One of the key features of PowerShell is its execution policy, which determines the level of trust required to run scripts on your computer. By default, PowerShell’s execution policy is set to restrict scripts to prevent malicious code from running. However, there are situations where you may need to change this policy, especially if you want to run custom or third-party scripts. In this topic, we’ll walk you through the steps to set the execution policy to Unrestricted, allowing you to run scripts without restrictions.
What is Execution Policy in PowerShell?
Before diving into how to change the execution policy, it’s essential to understand what an execution policy is. The execution policy is a security feature in PowerShell that determines whether scripts can be executed and which types of scripts can be run. There are several execution policy levels in PowerShell, including
-
Restricted No scripts can be run. This is the default setting.
-
AllSigned Only scripts signed by a trusted publisher can be run.
-
RemoteSigned Locally created scripts can run, but downloaded scripts must be signed by a trusted publisher.
-
Unrestricted No restrictions are applied to scripts. This allows all scripts to run, regardless of their source or signature.
The Unrestricted policy is the most permissive, allowing any script to be executed on your system. While it provides flexibility, it also carries risks, as potentially harmful scripts can be run without any restrictions. Therefore, it’s crucial to only use this setting when you trust the source of the scripts you’re running.
Why Set the Execution Policy to Unrestricted?
There are several reasons you might want to set the execution policy to Unrestricted
-
Running Custom Scripts If you’re developing your own scripts and want to run them without restrictions.
-
Running Third-Party Scripts Some third-party tools or packages may require the Unrestricted policy to run their scripts.
-
Testing Purposes If you need to quickly test a script without dealing with security-related restrictions.
How to Set Execution Policy to Unrestricted in PowerShell
Follow these steps to change the execution policy to Unrestricted
Step 1 Open PowerShell as Administrator
To modify the execution policy, you need to run PowerShell with administrative privileges. Here’s how
-
Press the Windows key, type PowerShell in the search bar.
-
Right-click on Windows PowerShell from the search results.
-
Select Run as administrator. This will open PowerShell with elevated privileges, which is required for changing system settings like the execution policy.
Step 2 Check Current Execution Policy
Before changing the execution policy, it’s a good idea to check the current policy to see what it’s set to. To do this, type the following command
Get-ExecutionPolicy
This command will return the current execution policy, such as Restricted, RemoteSigned, or another policy.
Step 3 Set the Execution Policy to Unrestricted
To set the execution policy to Unrestricted, type the following command and press Enter
Set-ExecutionPolicy Unrestricted
PowerShell will prompt you for confirmation before making the change. Type Y and press Enter to confirm.
Step 4 Verify the Change
After changing the execution policy, you can verify that the change was successful by running the following command again
Get-ExecutionPolicy
This should now return Unrestricted, confirming that the execution policy has been changed.
Understanding the Security Implications
While setting the execution policy to Unrestricted gives you the freedom to run all scripts, it also exposes your system to potential risks. Malicious scripts can be executed without any warnings or blocks, which could lead to data breaches or other security issues. Therefore, always ensure that you only run scripts from trusted sources.
How to Revert the Execution Policy to Its Default Setting
If you want to revert the execution policy to its default Restricted setting after setting it to Unrestricted, follow these steps
-
Open PowerShell as Administrator.
-
Run the following command to set the execution policy back to Restricted
Set-ExecutionPolicy Restricted -
Confirm the change by typing Y and pressing Enter.
Additional Execution Policy Options
In addition to Unrestricted, PowerShell offers other execution policy options that might be more suitable for your needs. These include
-
Restricted The default setting, which blocks all script execution.
-
AllSigned Only allows the execution of scripts signed by a trusted publisher.
-
RemoteSigned Allows locally created scripts but requires scripts downloaded from the internet to be signed.
-
Bypass Bypasses all execution policy restrictions (use with caution).
-
Undefined Removes the execution policy, allowing the policy to be inherited from a higher level.
You can set any of these policies by running the Set-ExecutionPolicy command followed by the policy you want to use. For example, to set the policy to RemoteSigned, run
Set-ExecutionPolicy RemoteSigned
How to Temporarily Change the Execution Policy
If you only need to change the execution policy temporarily for a single session, you can do so without making permanent changes. To do this, use the -Scope parameter when running the Set-ExecutionPolicy command. For example
Set-ExecutionPolicy Unrestricted -Scope Process
This will only change the execution policy for the current PowerShell session. Once you close the session, the execution policy will return to its previous state.
Changing the execution policy to Unrestricted in PowerShell is a straightforward process that allows you to run scripts without limitations. However, it’s important to understand the potential security risks associated with this setting. Always ensure that the scripts you are running come from trusted sources to avoid running malicious code on your system.
By following the steps outlined in this guide, you can easily adjust the execution policy to meet your needs and manage your scripts more efficiently in PowerShell.