Comprehensive Step-by-Step Guide to Modifying PowerShell Execution Policy for Script Execution

Key Notes

  • You can change the execution policy to allow or restrict script execution.
  • Policy settings can be applied locally or per user, affecting script execution scope.
  • Settings and commands both enable flexible modification of script permissions.

Unlocking Script Execution: How to Change PowerShell’s Execution Policy on Windows 10 and 11

When trying to run scripts in PowerShell, users may encounter errors due to restrictive execution policies. This guide provides a comprehensive walkthrough on adjusting these settings safely.

Understanding and Changing the PowerShell Execution Policy

To navigate PowerShell’s execution policy settings, follow these structured steps:

Step 1: Modify PowerShell Execution Policy via PowerShell

Begin by launching PowerShell with administrative privileges to make changes to the execution policy.

  1. Press Start on your Windows device.

  2. Type PowerShell, right-click on the result, and select Run as administrator.

  3. Check the current execution policy using this command and hit Enter : Get-ExecutionPolicy

  4. (Optional) To see the list of all policies, enter: Get-ExecutionPolicy -List

  5. To permit scripts to run, input the following command: Set-ExecutionPolicy RemoteSigned and hit Enter.

  6. (Optional) To restrict all script execution, type: Set-ExecutionPolicy Restricted and press Enter.

Upon completion, you will be prepared to execute your scripts on Windows 11 or 10.

Step 2: Adjust Execution Policy through Settings

You can also modify the PowerShell execution policy via the Windows Settings app. Here’s how:

For Windows 11

  1. Open Settings.
  2. Select System.
  3. Navigate to For developers.
  4. Click on the PowerShell option.
  5. Enable the toggle for “Change execution policy to allow local PowerShell scripts”.

For Windows 10

  1. Open Settings.
  2. Select Update & Security.
  3. Navigate to For developers.
  4. Enable the option for “Change execution policy to allow local PowerShell scripts”.
  5. Click Apply to save your changes.

After adjusting these settings, scripts classified as local will be permitted to run without a signature.

Step 3: Enable Running Unsigned Scripts

If you need to execute a script that is not digitally signed, follow these steps:

  1. Open Start and search for PowerShell.

  2. Right-click the top result, and choose Run as administrator.

  3. To allow unsigned scripts, enter the following command and hit Enter : Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Run your script with the command .\Your-PowerShell-Script.ps1 within the same session. Remember, changes made with the Process scope last only until PowerShell is closed.

Additional Tips

  • Consider using the Bypass parameter for non-interactive script execution.
  • Always verify the source of external scripts before allowing them to run.
  • Adjusting execution policies can enhance security but must be managed carefully.

Summary

This guide detailed a step-by-step process for changing the PowerShell execution policy on Windows 10 and 11, allowing users to enable or restrict script execution according to their needs while adhering to best security practices.

Conclusion

Understanding how to modify the PowerShell execution policy is vital for running scripts efficiently and securely. Ensure to choose the appropriate policy that aligns with your script execution needs, balancing functionality with system security.

FAQ (Frequently Asked Questions)

What is the default execution policy for PowerShell?

The default execution policy is typically set to “Restricted, ” which prevents any scripts from running.

How can I verify my current execution policy?

You can verify your current execution policy by using the command Get-ExecutionPolicy in an elevated PowerShell window.