In Windows 11, PowerShell has an “execution policy” security feature that controls how to load configuration files and run scripts to prevent malicious code from running on the system. So sometimes when trying to run a script on PowerShell, it will fail with the “cannot be loaded because running scripts is disabled on this system” error message.
If you are trying to run a script in Windows 11, you will need to change the execution policy for the local computer, current user, or session.
When you set a PowerShell execution policy for the local computer and current user, the information will be stored in the Registry. However, if you configure the policy for a particular session, the policy will be held in memory and then lost when you close the session. According to Microsoft, the execution policy doesn’t restrict the action. You can bypass the policy by typing the script in the command-line interface (CLI).
In this guide, we will show you how to change the execution policy to run scripts successfully on PowerShell in Windows 11.
How to change the execution policy in PowerShell
- Click on the Start > search for PowerShell > select the Run as administrator option.
- Type the following command to confirm the current execution policy > press Enter on the keyboard.
- Type the following command to change the PowerShell execution policy to allow scripts > press Enter on the keyboard.
- Type Y > press Enter on the keyboard.
- When done, you can now execute the script again, and it should now run successfully in Windows 11.